It looks like you're new here. If you want to get involved, click one of these buttons!
cls;
$minDate = "2016-01-01";
$yaSymbolList = "MSFT, AAPL,TD.TO,XRE.TO";
$urlBase = "http://ichart.finance.yahoo.com/table.csv?s=@@Symbol@@&a=@@STARTMTH@@&b=@@STARTDAY@@&c=@@STARTYEAR@@&g=d&ignore=.csv";
$scriptPath = Split-Path -parent $MyInvocation.MyCommand.Definition; if (!(Test-Path -Path ($scriptPath+"\Quotes"))) {New-Item ($scriptPath+"\Quotes") -type directory};
$quoteIDFileYA = $scriptPath+"\Quotes\YahooIntraday.txt"; if (Test-Path $quoteIDFileYA) { Remove-Item $quoteIDFileYA;}
ForEach ($s in @($yaSymbolList.split(","))) {
$symbol = $s.Trim();$symbolQuoteFile = $scriptPath + "\Quotes\_" + $symbol.Replace(":","_").Replace("^","_").Replace("&","_") + "_" + ".txt"; $lastDateInFile="";
if (Test-Path -Path $symbolQuoteFile) {$fc = @(import-csv $symbolQuoteFile -Header "Date","Close","Symbol" | Sort-Object -Property "Date"); if ($fc.count -gt 0) {$lastDateInFile = $fc[$fc.count-1].Date;} }
if ($lastDateInFile -ne "") {$nextDate = ([datetime]::ParseExact($lastDateInFile,”yyyy-MM-dd”,$null)).AddDays(1).ToString("yyyy-MM-dd"); } else {$nextDate = $minDate;}
$year = $nextDate.Substring(0,4); $month = [int]$nextDate.Substring(5,2) - 1; $day = $nextDate.Substring(8,2);
@Symbol@@STARTMTH@@STARTDAY@@STARTYEAR@@",$year);
$wc = new-object system.net.WebClient; try {$webpage = $wc.DownloadData($url);} catch { "Symbol $symbol no data"; continue;}
$quotesTxt = [System.Text.Encoding]::ASCII.GetString($webpage); if ($quotesTxt.length -le 45 -or $quotesTxt.Contains("")) {"$symbol- No new data received."; continue;}
$ql = $quotesTxt.Split("`n");
$ql | ? {$_.trim() -ne "" -and ($_.StartsWith("1") -or $_.StartsWith("2"))} | %{$a=$_.Split(","); $a[0]+","+$a[4]+","+$symbol; } | Out-File $symbolQuoteFile -Encoding OEM -Append;
"Symbol $symbol done. New record count: " + $ql.Count;
}
Comments
Is there any chance that you could be able to write such scripts adjusted for Portfolio Slicer requirements? As per documentation, we need external data file: ”CurrencyConv.csv“ ,”Quotes.csv“ ,”Dividends.csv”.
If possible, could you extend psConfig.txt file to include parameters for Yahoo/Google?
TIA!
I'll see what I can do. I'll check your new PS version and if all looks good, I'll migrate my very old PS workbook to this new release As I'll need data, I will adjust my existing scripts, so I'll share them here. Give me few days, maybe a week.
I created PowerShell scripts that will get data from websites. But I cannot find a way to attach them to this post. I see link "Attach image/file", but when I click on it, it does not work.
I see your problem, but I am not sure how to fix this now. Could you please save files on DropBox or OneDrive or GDrive and share them through these services and post link here? Also, could you start new thread, if scripts are working, I'll make thread "sticky" as this would be very helpful scripts to many users.
TIA!
I posted new thread with link to DropBox file here: http://new.portfolioslicer.com/support/index.php?p=/discussion/5/scripts-to-get-data-for-portfolio-slicer-from-yahoo-google-and-boc?new=1
Please let me know if you have any issues with this script.
Maxim.