Price Performance Extension Sample
<pss_extension name="Price Performance Report" version="1.0.5"> A simple performance report
<author email="support@dtlink.com" name="DTLink Software" url="http://www.dtlink.com" />
<script language="VBScript">
<![CDATA[
' Price performance report for Personal Stock Streamer
' Copyright © 2004-2005 by DTLink Software, All rights reserved.
' http://www.dtlink.com
' written by Anatoly Ivasyuk
' A simple price performance report
' ================================================
' define the report handler class
class PriceReportHandler
' create the report
public Function GenerateReport ( Name, Handler, Folder )
' Application.DebugTrace "PriceReportHandler::GenerateReport(" + Name + ")"
' generate report header
Handler.WriteReport "<body bgcolor=White>"
If (Handler.FilterPeriod = "All Available Data") Then
Handler.WriteReport "<b>Please select a smaller date range</b>"
Else
Handler.WriteReport "<b>Performance Report for " + Handler.FilterPeriod + "</b>"
Handler.WriteReport "<table border=0 cellpadding=0 cellspacing=10>"
Handler.WriteReport "<tr><th><b>Symbol</b></th><th><b>Starting Price</b></th><th><b>Ending Price</b></th><th><b>Gain</b></th><th><b>% Gain</b></th></tr>"
' generate report body
RecurseFolder Handler, Folder
Handler.WriteReport "</table>"
End If
Handler.WriteReport "</body>"
end Function
public Function RecurseFolder ( Handler, Folder )
' process the tickers in the folder
Set Tickers = Folder.Tickers
' Application.DebugTrace "PriceReportHandler::RecurseFolder() Tickers.Count = " + CStr(Tickers.Count)
For i = 1 To Tickers.Count
' Application.DebugTrace "PriceReportHandler::RecurseFolder() ticker=" + Tickers.Item(i).GetProperty("Symbol")
' only calculate gain for non-cash tickers
If (Tickers.Item(i).GetProperty("Cash") = False) Then
' get the history data for this year
Tickers.Item(i).SetProperty "HistoryStart", Handler.FilterDateStart
Tickers.Item(i).SetProperty "HistoryEnd", Handler.FilterDateEnd
Set History = Tickers.Item(i).HistoryData
' check to make sure we actually have historical data
If Not History Is Nothing And History.Count > 0 Then
' get the first and last trading data for the selected time period and calculate the difference
BeginValue = History.Item(0).GetProperty("Close")
EndValue = History.Item(History.Count - 1).GetProperty("Close")
Diff = EndValue - BeginValue
DiffPct = ((EndValue - BeginValue) / BeginValue) * 100
Handler.WriteReport "<tr><td>" + Tickers.Item(i).GetProperty("Symbol") + "</td>"
Handler.WriteReport "<td align=right>" + FormatNumber(BeginValue,2) + "</td><td align=right>" + FormatNumber(EndValue,2) + "</td>"
Handler.WriteReport "<td align=right>" + FormatNumber(Diff,2) + "</td><td align=right>" + FormatNumber(DiffPct,2) + "</td></tr>"
' otherwise download historical data
Else
Handler.WriteReport "<tr><td>" + Tickers.Item(i).GetProperty("Symbol") + "</td>"
Handler.WriteReport "<td align=right>Waiting for Data</td>"
Tickers.Item(i).DownloadHistoryData Handler.FilterDateStart, Handler.FilterDateEnd
End If
End If
Next
' recursively loop through the subfolders
Set Folders = Folder.Folders
For i = 1 To Folders.Count
RecurseFolder Handler, Folders.Item(i)
Next
end Function
public Function OnHistoryUpdated ( Ticker )
' we only care about this event if the user is looking at the Reports view
If (Application.GetCurrentView() = "Reports") Then
' Application.DebugTrace "PriceReportHandler::OnHistoryUpdated() ticker=" + Ticker.GetProperty("Symbol")
' we want to go through the app timer event because OnHistoryUpdated will be called once
' for every ticker that is updated and we don't want to update the report multiple times
Set EventManager = Application.GetObject("EventManager")
EventManager.RegisterHandlerMethod me, "OnAppTimer"
End If
End Function
public Function OnAppTimer
' Application.DebugTrace "PriceReportHandler::OnAppTimer()"
' make sure we don't get called repeatedly, unnecessarily
EventManager.UnregisterHandlerMethod me, "OnAppTimer"
' now that we have the historical data we requested, update the report
Set ReportManager = Application.GetObject("ReportManager")
ReportManager.UpdateCurrentReport
End Function
end Class
' ================================================
' register the custom report with the application
Dim ReportHandler
Set ReportHandler = new PriceReportHandler
Dim ReportManager
Set ReportManager = Application.GetObject("ReportManager")
If Not ReportManager Is Nothing Then
ReportManager.Register "Price Performance", ReportHandler
Else
Application.DebugTrace "Could not get ReportManager object"
End If
Set EventManager = Application.GetObject("EventManager")
If Not EventManager Is Nothing Then
EventManager.RegisterHandlerMethod ReportHandler, "OnHistoryUpdated"
Else
Application.DebugTrace "Could not get ReportManager object"
End If
]]>
</script>
</pss_extension>