Click here to Login





                                                   Can a csv field be set to NaN?

  0

0
Chaim6
2014-01-30 10:43:25


When downloading Morningstar data, it is common to have missing information. For example, see 2009 Cap Spending for Toyato in http://financials.morningstar.com/ratios/r.html?t=7203&region=jpn&culture=en-US&ownerCountry=USA. It's obvious that the number is not 0. Yet the C# parser must initialize all fields to 0 in order for the parser to work properly. A blank field gets converted to 0 automatically. I would like to set it to NaN. Is that possible?

Thanks.



QuantShare
2014-01-30 20:03:05

  0

Yes, in the POST-Script, check for zeros and updates that the field to: double.NaN


Chaim6
2014-01-31 05:18:32

  0

Okay, here's what I tried in the Post-Script:

for (int iRow = 1; iRow < Data.Rows.Length; iRow++)
for (int iCol = 1; iCol < Data.Rows[iRow].Data.Length; iCol++)
if (unchecked((double)Data.Rows[iRow].Data[iCol]) == 0)
Data.Rows[iRow].Data[iCol] = Double.NaN;

It compiles ok, but I get a Post-Script execution error:
"Specified cast is not valid."

How do I fix this code?

Thanks.



QuantShare
2014-01-31 13:23:51

  0

Try this:

for (int iRow = 0; iRow < Data.Rows.Length; iRow++)
for (int iCol = 0; iCol < Data.Rows[iRow].Data.Length; iCol++)
{
object obj = Data.Rows[iRow].Data[iCol];
if(obj is double && (double)obj == 0)
{
Data.Rows[iRow].Data[iCol] = Double.NaN;
}
}




Chaim6
2014-01-31 20:55:53

  0

That put me on the right track. I ended up using:
for (int iRow = 0; iRow < Data.Rows.Length; iRow++)
for (int iCol = 0; iCol < Data.Rows[iRow].Data.Length; iCol++)
{
double d;
if(double.TryParse(Convert.ToString(Data.Rows[iRow].Data[iCol]), out d) && d == 0)
{
Data.Rows[iRow].Data[iCol] = Double.NaN;
}
}
because the 0's for some reason were not of type double. Thanks.



No more messages
0




Reply:

No html code. URLs turn into links automatically.

Type in the trading objects you want to include: - Add Objects
To add a trading object in your message, type in the object name, select it and then click on "Add Objects"










QuantShare

Trading Items
Portfolio Statistics to CSV File
Sum of a Custom Database's Field
Update the Stock Exchange Associated With U.S. Stocks - Market Fi...
Set Global Variable
Set the First Trading Bar Values to Not a Number

How-to Lessons
How to quickly select stocks based on the last value of a databas...
How to import trading data from CSV files
How to set order type of a trading system programmatically
How to export trading data to a CSV file
How to import trades into a portfolio

Related Forum Threads
How can I set Log Scale charts?
How can I associate a field (value) to a trade in a MM script?
Automatically create field names for columns in ASCII import
Ability to Set Default Text Size in Editor Windows
Ingest earnings data from csv file ..

Blog Posts
5 position sizing techniques you can use in your trading system
Trading software new features
The Ultimate Guide to Create Trading Systems in QuantShare
Different Ticker Symbols for Each Data Source
Create Profitable Trading Strategies with Exchange Traded Funds (...









QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.