I am looking to write to a file a table of data. This is how it should look:
Column 1 = date
Column 2-21 = daily net profit time series for each iteration of an input from value 1 to 20
Row 1 Labels are Date, Iteration # (if possible)
If the code only allows me to generate rows - no problem, I can transpose it all in excel later.
Any ideas?
Exporting a Profit Table from an optimization
- Dave Masalov
- Posts: 1712
- Joined: 16 Apr 2010
- Has thanked: 51 times
- Been thanked: 489 times
Re: Exporting a Profit Table from an optimization
Dear evanscje,
Please take a look on 'FileAppend' and 'print' functions in PLE. They allow you to write the data to the text file, which you can then import in Excel.
Please take a look on 'FileAppend' and 'print' functions in PLE. They allow you to write the data to the text file, which you can then import in Excel.
Re: Exporting a Profit Table from an optimization
I am very familiar with the function .. my problem is with this specific application :
I need to append a file with additional columns for every optimization iteration
I need to append a file with additional columns for every optimization iteration
Re: Exporting a Profit Table from an optimization
Here's what I have so far:
variables:
int ArrayIndex( 0 ) ;
arrays:
Double NetProfitArray[10000]( 0 ),
Int TradesArray[10000]( 0 ),
Int DateArray[10000]( 0 ) ;
// If the prior bar date is not equal to the current bar date then this is a new day.
// Capture the date, netprofit, associated with the first bar
// of the new day.
if Date[1] <> Date then
begin
NetProfitArray[ArrayIndex] = NetProfit ;
TradesArray[ArrayIndex] = TotalTrades ;
DateArray[ArrayIndex] = Date ;
// Increment the array index by one for each new day.
ArrayIndex = ArrayIndex + 1 ;
// If the array index exceeds the maximum array size of 100 then issue an error
// to halt the strategy and inform you that the array sizes must be increased
if ArrayIndex > 10000 then
RaiseRunTimeError(" Increase sizes of NetProfit." ) ;
end ;
// Output the array values on the last bar of the chart each time after the strategy has completely run for a given optimization
If LastBarOnChart then
begin
// Add a "Date", "NetProfit" and "#Trades" value to the record for each increment of the ArrayIndex
for Value1 = 0 to ArrayIndex - 1
begin
FileAppend("C:\test5.csv", NumToStr( DateArray[Value1], 0 ) + "," );
FileAppend("C:\test5.csv", NewLine) ;
FileAppend("C:\test5.csv", NumToStr( NetProfitArray[Value1], 2 ) + "," ) ;
end ;
end ;
This does produce columns! .. the first column is profit (why is it not in column 2?) and the second column is date (in a format that Excel can’t read) When I run an optimization only those 2 columns are produced ??
Any help would be much appreciated
variables:
int ArrayIndex( 0 ) ;
arrays:
Double NetProfitArray[10000]( 0 ),
Int TradesArray[10000]( 0 ),
Int DateArray[10000]( 0 ) ;
// If the prior bar date is not equal to the current bar date then this is a new day.
// Capture the date, netprofit, associated with the first bar
// of the new day.
if Date[1] <> Date then
begin
NetProfitArray[ArrayIndex] = NetProfit ;
TradesArray[ArrayIndex] = TotalTrades ;
DateArray[ArrayIndex] = Date ;
// Increment the array index by one for each new day.
ArrayIndex = ArrayIndex + 1 ;
// If the array index exceeds the maximum array size of 100 then issue an error
// to halt the strategy and inform you that the array sizes must be increased
if ArrayIndex > 10000 then
RaiseRunTimeError(" Increase sizes of NetProfit." ) ;
end ;
// Output the array values on the last bar of the chart each time after the strategy has completely run for a given optimization
If LastBarOnChart then
begin
// Add a "Date", "NetProfit" and "#Trades" value to the record for each increment of the ArrayIndex
for Value1 = 0 to ArrayIndex - 1
begin
FileAppend("C:\test5.csv", NumToStr( DateArray[Value1], 0 ) + "," );
FileAppend("C:\test5.csv", NewLine) ;
FileAppend("C:\test5.csv", NumToStr( NetProfitArray[Value1], 2 ) + "," ) ;
end ;
end ;
This does produce columns! .. the first column is profit (why is it not in column 2?) and the second column is date (in a format that Excel can’t read) When I run an optimization only those 2 columns are produced ??
Any help would be much appreciated
- Dave Masalov
- Posts: 1712
- Joined: 16 Apr 2010
- Has thanked: 51 times
- Been thanked: 489 times
Re: Exporting a Profit Table from an optimization
Dear evanscje,
Firstly, you write to the file with the "," divider:
Why do you add newline before netprofit value? It is understandable why NetProfit is the first column.
Please try this one:
It is more convinient to add data for Date in Julian format
Then, if you set the right sell format in Excel, it will recognize the date.
Firstly, you write to the file with the "," divider:
Code: Select all
begin
FileAppend("C:\test5.csv", NumToStr( DateArray[Value1], 0 ) + "," );
FileAppend("C:\test5.csv", NewLine) ;
FileAppend("C:\test5.csv", NumToStr( NetProfitArray[Value1], 2 ) + "," ) ;
end ;
Please try this one:
Code: Select all
begin
FileAppend("C:\test5.csv", NumToStr( DateArray[Value1], 0 ) + "," + NumToStr( NetProfitArray[Value1], 2 ) + ",");
FileAppend("C:\test5.csv", NewLine) ;
end ;
Code: Select all
DateArray[ArrayIndex] = datetojulian(Date) ;