Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query Finance API for Stocks #152

Merged
merged 7 commits into from
May 16, 2021
Merged

Query Finance API for Stocks #152

merged 7 commits into from
May 16, 2021

Conversation

jonpsy
Copy link
Member

@jonpsy jonpsy commented May 12, 2021

@zoq This PR is from our discussion yesterday. Let me know if I'm missing something? Thanks

@mlpack-bot
Copy link

mlpack-bot bot commented May 12, 2021

Thanks for opening your first pull request in this repository! Someone will review it when they have a chance. In the mean time, please be sure that you've handled the following things, to make the review process quicker and easier:

  • All code should follow the style guide
  • Documentation added for any new functionality
  • Tests added for any new functionality
  • Tests that are added follow the testing guide
  • Headers and license information added to the top of any new code files
  • HISTORY.md updated if the changes are big or user-facing
  • All CI checks should be passing

Thank you again for your contributions! 👍

Comment on lines 8 to 11
int PortFolio(const std::string& stock0,
const std::string& stock1,
const std::string& stock2,
const std::string& stock3,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use a list/vector here, to make it possible to select an arbitrary number of stocks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point, but for pArgs = PyTuple_New(???); how do we solve this dilemma?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vector.size() should work right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nvm

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah figured it a bit late, sorry ;D

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, I think it's still early for you?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's 08;00AM :) ,

utils/portfolio.py Outdated Show resolved Hide resolved
@jonpsy
Copy link
Member Author

jonpsy commented May 14, 2021

How about we allow the user to choose the finance API as well and not restrict it to just Yahoo? I did some digging in the code and found the following are available:

    expected_source = [
        "yahoo",
        "iex",
        "iex-tops",
        "iex-last",
        "iex-last",
        "bankofcanada",
        "stooq",
        "iex-book",
        "enigma",
        "fred",
        "famafrench",
        "oecd",
        "eurostat",
        "nasdaq",
        "quandl",
        "moex",
        "tiingo",
        "yahoo-actions",
        "yahoo-dividends",
        "av-forex",
        "av-forex-daily",
        "av-daily",
        "av-daily-adjusted",
        "av-weekly",
        "av-weekly-adjusted",
        "av-monthly",
        "av-monthly-adjusted",
        "av-intraday",
        "econdb",
        "naver",
    ]

If the user enters the wrong data source the Python interface throws NotImplementedError which should reflect in portfolio.hpp. Am I correct?

@jonpsy jonpsy changed the title Query Yahoo Finance API for Stocks Query Finance API for Stocks May 14, 2021
@jonpsy
Copy link
Member Author

jonpsy commented May 14, 2021

Also, perhaps we should store generated csv file in a designated folder like "temp/" or something, no?

@zoq
Copy link
Member

zoq commented May 14, 2021

Also, perhaps we should store generated csv file in a designated folder like "temp/" or something, no?

Maybe it makes sense the user can specify a path + filename and if the path doesn't exist we create it.

How about we allow the user to choose the finance API as well and not restrict it to just Yahoo? I did some digging in the code and found the following are available:

Sounds like a good idea to me, in the end it's more about the optimization method, but it's nice to have a solid data generation method as well.

If the user enters the wrong data source the Python interface throws NotImplementedError which should reflect in portfolio.hpp. Am I correct?

Ideally yes, put sometimes the exception are not handed over to the notebook, but I'm not worried about that if we don't handle certain corner cases, as I mentioned above the main focus of the notebook is on the optimization method.

- any data source is valid
@jonpsy
Copy link
Member Author

jonpsy commented May 14, 2021

Great suggestions, have applied them all. The style check errors seem to be independent of this PR. Do you mind confirming this?

@zoq
Copy link
Member

zoq commented May 14, 2021

@mlpack-jenkins test this please

@zoq
Copy link
Member

zoq commented May 14, 2021

Great suggestions, have applied them all. The style check errors seem to be independent of this PR. Do you mind confirming this?

A jenkins job I haven't updated, looks like it works now as expected.

Copy link
Member

@zoq zoq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting everything together, looks good to me.

# Drop the first row since it contains NaN.
returns = returns.iloc[1:]
# Normalize dates.
returns['Date'] = returns['Date'].apply(lambda x : x.strftime('%Y%m%d'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@jonpsy
Copy link
Member Author

jonpsy commented May 15, 2021

Great, once this is merged. I'll immediately start working on the notebook. Super-easy, barely an inconvenience!

Copy link

@mlpack-bot mlpack-bot bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second approval provided automatically after 24 hours. 👍

@zoq zoq merged commit 6532728 into mlpack:master May 16, 2021
@zoq
Copy link
Member

zoq commented May 16, 2021

Thanks again!

@jonpsy jonpsy deleted the portfolio branch May 16, 2021 00:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants