pwnaz0r
2008-10-19 00:21:21
Ok so cool, I deleted the whole first post thing.
Anyways, in short, I'm getting into stocks, the American Economy and such, so I decided to make this. If you use, be sure to make debug wide enough. Maybe you use for studying purposes (even though I don't think its that advanced :p), anyways, it predicts if you should buy, sell, anything really stocks at different times, assesses analyst reports, and gives you a success ratio.
Anyways, in short, I'm getting into stocks, the American Economy and such, so I decided to make this. If you use, be sure to make debug wide enough. Maybe you use for studying purposes (even though I don't think its that advanced :p), anyways, it predicts if you should buy, sell, anything really stocks at different times, assesses analyst reports, and gives you a success ratio.
program PageTests;
const
StockTicker = 'SAF';
Detailed = true; //Reports details, like (+ \ -) of each analysis
SuggestStockTicker = false;// Suggests a stockticker.
var
MyTime: integer;
function RemoveAllTags(Report: string): string;
var
TheString: string;
begin
Result:= Replace(Result, '</font>', '');
Result:= Replace(Result, '<b>', '');
Result:= Replace(Result, ' ', ' Nothing');
Result:= Replace(Result, 'amp;', '');
end;
function ConvertTimeToStr(time: integer): string;
var
H, S, M : integer;
HS, MMS, SS: string;
begin
ConvertTime(Time, H, M, S);
if (H > 0)then
begin
H:= H mod 24;
HS:= IntToStr(H);
end else Hs:= '00';
SS:= IntToStr(S);
if (S <= 9)then
SS:= '0'+IntToStr(s);
MMS:= IntToStr(M);
if (M <= 9)then
MMS:= '0'+IntToStr(M);
Result:= HS+':'+MMS+':'+SS;
end;
function GetPageStuff(Ticker: string): array of String;
var
WPageHTML, WPageHTMLEx: string;
I, X: integer;
begin
SetArrayLength(result, 0);
WPageHTML:= GetPage('http://finance.yahoo.com/q/ao?s=' + Ticker);
I:= 0;
X:= 0;
repeat
Inc(X);
i:= Pos('nowrap align="right">', WPageHTML);
if (I < 1)then break;
SetArrayLength(result, GetArrayLength(result) + 1);
result[(High(result))]:= Between('nowrap align="right">', 'nowrap align="right">', WPageHTML);
result[(High(result))]:= Replace(result[(high(result))], '</td><td class="yfnc_tabledata1">', ' : ');
result[(High(result))]:= Replace(result[(high(result))], '</td><td class="yfnc_tabledata1" align="center"><font color="green">', ' --> ');
result[(High(result))]:= Replace(result[(high(result))], '</td><td class="yfnc_tabledata1" align="center"><font color="red">', ' --> ');
result[(High(result))]:= Replace(result[(high(result))], '</td><td class="yfnc_tabledata1" align="center">', ' --> ');
result[(High(result))]:= Replace(result[(high(result))], '</td><td class="yfnc_tabledata1" align="center"><font color="red">', ' --> ');
result[(High(result))]:= Replace(result[(high(result))], '</font></td><td class="yfnc_tabledata1" align="center">', ' | From: ');
result[(High(result))]:= Replace(result[(high(result))], '</td><td class="yfnc_tabledata1" align="center"><b>', ' | To: ');
result[(High(result))]:= Replace(result[(high(result))], '</b></td></tr><tr><td class="yfnc_tabledata1"', '');
result[(High(result))]:= RemoveAllTags(result[(High(result))]);
WPageHTML:= Copy(WPageHTML, Pos('</b></td></tr><tr><td class="yfnc_tabledata1', WPageHTML)+1, High(WPageHTML));
until(X > 12);
end;
function FixReports(var Reports: array of String): array of String;
var
I: integer;
TestStr: array of String;
begin
for I:= 0 to High(Reports) do
begin
SetLength(TestStr, 0);
SetLength(TestStr, 3);
TestStr[0]:= Between(': ', ' -->', Reports[i]);
if (Length(TestStr[0]) > 13) then
Begin
SetLength(TestStr[0], 11);
TestStr[0]:= TestStr[0] + '..';
end else
SetLength(TestStr[0], 13);
{ TestStr[1]:= Between('--> ', ' | ', Reports[i]);
SetLength(TestStr[1], 9);
TestStr[2]:= Between('e | F', 'uy', Reports[i]) + 'uy';
result[(i)]:= TestStr[0] + ' --> ' + TestStr[1] + ' | '+ TestStr[2]; }
end;
end;
function HighestLength(Strings: array of string): integer;
var
I: integer;
begin
for I:= Low(Strings) to High(Strings) do
if (Length(Strings[i]) > result)then
result:= Length(Strings[i]);
end;
procedure OtherStockInfo(Ticker: string);
var
TheString, TheOtherString: string;
begin
TheString:= GetPage('http://finance.yahoo.com/q?s='+Ticker);
TheOtherString:= Between('"yfs_l10_', '</', TheString);
Writeln(' | Last Trade : ' + TheOtherString);
end;
procedure WriteAnalystReport(ticker: string);
var
Reports: array of string;
I, L: integer;
begin
ClearDebug;
//Writeln (Padl('--> ', 15) + 'Stock Information are as follows:' + Padr(' <--', 15));
//OtherStockInfo(Ticker);
Writeln(Padl('--> ', 23) + 'STOCK TICKER : '+Ticker+ Padr(' <--', 15));
Writeln(Padl('--> ', 13) + 'This Report was conducted on '+ DateToStr(Date)+ Padr(' <--', 15));
Writeln(Padl('--> ', 27) + DateToStr(Date)+ Padr(' <--', 15));
Writeln(Padl('--> ', 28) + ConvertTimeToStr(GetSystemTime)+ Padr(' <--', 15));
Writeln('');
Writeln(Padl('--> ', 15) + 'Analyst reports for are as follows:' + Padr(' <--', 15));
Writeln('');
reports:= GetPageStuff(Ticker);
//L:= HighestLength(Reports) + 2;
//Reports:= FixReports(Reports);
Writeln(' /-------------------------------------------------------------------------------------\');
for I:= 0 to High(reports)do
begin
if ((reports[i]) = '')then
break;
if (Pos(':', reports[i]) = 10)then
Writeln(' | 0' + Reports[i] + Padl(' | ', 84 - length(Reports[i]))) else
Writeln(' | ' + Reports[i] + Padl(' | ', 85 - length(Reports[i])));
end;
Writeln(' \-------------------------------------------------------------------------------------/');
end;
function AnalyzeRatings(Rating: extended): string;
begin
if (Rating >= 1.25)then
Result:= ' Strong Buy' else
if (Rating >= 1.00)then
Result:= 'Buy' else
if (Rating >= 0.90)then
Result:= 'Overperform, Cautious Buy' else
if (Rating >= 0.75)then
Result:= 'Mkt Perform' else
if (Rating >= 0.5)then
Result:= 'Hold' else
if (Rating >= 0.25)then
Result:= 'Mkt Underperform' else
// if (Rating >= 0.0)then
// Result:= 'Get out of there' else
if (Rating > 0.0)then
Result:= 'Sell' else
Result:= 'Strong Sell';
end;
function ExtToStr(Value: extended): string;
var
Value1: variant;
begin
Value1:= Value;
result:= Value1;
end;
procedure AnalyzeReports;
var
Reports: array of String;
I, Rating, OldRating: integer;
begin
Reports:= GetPageStuff(StockTicker);
for I:= high(Reports) downto Low(Reports) do
if Reports[I] = '' then
SetLength(Reports, I) else break;
if (Detailed) then
begin
ClearReport;
AddToReport(' /-------------------------\');
AddToReport(' | Analyst (+/-) |');
AddToReport(' \-------------------------/');
AddToReport('');
end;
for I:= Low(Reports) to High(Reports) do
begin
OldRating:= Rating;
if (Pos('Initiated', Reports[i]) <> 0)then
begin
if (Pos('Sell', Reports[i]) <> 0) or (Pos('Under', Reports[i]) <> 0) then
Rating := Rating - 1 else Rating:= Rating + 1;
end;
if (Pos('Upgrade', Reports[i]) <> 0)then
begin
if (Pos('Out', Reports[i]) <> 0) or (Pos('Buy', Reports[i]) <> 0) then
Rating:= Rating + 2 else Rating:= Rating + 1;
end;
if (Pos('Downgrade', Reports[i]) <> 0)then
begin
if (Pos('Sell', Reports[i]) <> 0) then
Rating:= Rating - 2 else Rating:= Rating - 1;
end;
if (Oldrating = Rating)then
begin
Writeln('No Point value could be dervied from Stock Analyst['+IntToStr(I)+']');
end else
if (Detailed) then
if (OldRating < Rating)then
AddToReport(' Analyst['+IntToStr(I)+'] + '+IntToStr(Rating - Oldrating)) else
AddToReport(' Analyst['+IntToStr(I)+'] - '+IntToStr(Oldrating - Rating));
end;
Writeln('');
Writeln(Padl('--> ', 23) + ' Analysis Information '+ Padr(' <--', 15));
Writeln('');
Writeln(' /--------------------------------------------------------------------------------\');
try
if (Pos(':', reports[(High(Reports))]) = 10)then
Writeln(' | Buy rating since '+Copy(Reports[(High(Reports))], 1, 9)+ ': ' + IntToStr(Rating)+' / '+IntToStr(High(Reports)) + ' or '+ ExtToStr((Rating / High(Reports)) * 100) + '% success rate'+ Padl(' | ', 84 - length(' | Buy value since '+Copy(Reports[(High(Reports))], 1, 9)+ ': ' + IntToStr(Rating)+' / '+IntToStr(High(Reports)) + ' or '+ ExtToStr((Rating / High(Reports)) * 100) + '% success rate'))) else
Writeln(' | Buy rating since '+Copy(Reports[(High(Reports))], 1, 9)+ ': ' + IntToStr(Rating)+' / '+IntToStr(High(Reports)) + ' or '+ ExtToStr((Rating / High(Reports)) * 100) + '% success rate'+ Padl(' | ', 83 - length(' | Buy value since '+Copy(Reports[(High(Reports))], 1, 8)+ ': ' + IntToStr(Rating)+' / '+IntToStr(High(Reports)) + ' or '+ ExtToStr((Rating / High(Reports)) * 100) + '% success rate')));
except
Writeln(' | Analysis based on current information : Pick a freaking valid ticker :)');
Writeln(' \--------------------------------------------------------------------------------/');
TerminateScript;
end;
Writeln(' | Trend based on current information : '+ AnalyzeRatings( Rating / High(Reports) ) + Padl(' | ', 88 - length(' | Analysis based on current information : '+ AnalyzeRatings( Rating / High(Reports) ))) );
Writeln(' | It it advised to go against the above trend in order to maximize profits |');
Writeln(' \--------------------------------------------------------------------------------/');
end;
procedure ScriptTerminate;
begin
writeln('');
Writeln(' /----------------------------------------------------------------\');
Writeln(Padr(' |', 26) + '--> Credits <--' + Padl('|', 27));
Writeln(Padr(' |', 8) +'All stocks, information, or anything outside of user'+ Padl('|', 8));
Writeln(Padr(' |', 8) +'programming is made made possible by and retrieved by'+ Padl('|', 7));
Writeln(Padr(' |', 8) +'Copyright © 2008 Yahoo! Inc. All rights reserved.'+ Padl('|', 11));
Writeln(Padr(' |', 21) + '--> Finance.Yahoo.Com <--' + Padl('|', 22));
Writeln(' \----------------------------------------------------------------/');
Writeln('');
Writeln(' Took '+IntToStr(getSystemTime-MyTime)+' msec.');
end;
procedure DoSuggest;
begin
ClearDebug;
Writeln('Program suggests '+Between( '<a href="http://app.quotemedia.com/quotetools/clientForward?targetURL=http://www.powerratings.net/investors/quotescharts/?qm_symbol=', '&action=showProfile">', GetPage('http://www.powerratings.net/investors/toplist/?hcode=lrmenu')));
Writeln('Courtesy of http://www.powerratings.net/investors/toplist/');
end;
begin
MyTime:= GetSystemTime;
if (SuggestStockTicker)then
begin
DoSuggest;
TerminateScript;
end;
WriteAnalystReport(StockTicker);
AnalyzeReports;
end.