Marigold / universal-portfolios

Collection of algorithms for online portfolio selection
Other
778 stars 214 forks source link

specifying the args of CORN class #83

Closed shayandavoodii closed 2 years ago

shayandavoodii commented 2 years ago

Hi, I'm trying to use your code for implementing the CORN strategy, But I'm confused about using it because of poor documentation. So, combining the CORN paper and your codes, I got a light taste, But not adequate.

So I decided to open an issue to get help from you. CORN class has three optional initial options, namely, window, rho, fast_version which are explicit. But to get the job done, there are further options in init_step module like X and step_slow module like x, last_b, history which are not explicitly explained about their identity and meaning, But I guess some of them, which I need to know which one is true:

Can you please shed light on these variables? Then I can properly give the correct values to these modules.
Thank you so much.

Marigold commented 2 years ago

Hey @shayandavoodii, to run CORN (or any other algorithm) you just call e.g.

S = ... dataframe with RAW prices
algo = CORN(window=10, rho=0.1)
result = algo.run(S)

print(result.summary())
result.plot(weights=False, assets=False, ucrp=True, logy=True);

the other methods like init_step or step_slow are internal (should have been prefixed with underscore) and you don't need need to know about them. What is interesting for analysis are methods and attributes of result from the code above.

shayandavoodii commented 2 years ago

Hey @shayandavoodii, to run CORN (or any other algorithm) you just call e.g.

S = ... dataframe with RAW prices
algo = CORN(window=10, rho=0.1)
result = algo.run(S)

print(result.summary())
result.plot(weights=False, assets=False, ucrp=True, logy=True);

the other methods like init_step or step_slow are internal (should have been prefixed with underscore) and you don't need need to know about them. What is interesting for analysis are methods and attributes of result from the code above.

Hi! Thanks for your response! I have two other questions:

  1. Does this approach work for the other algorithms? example:
    algo=[ANOTHER_ALGORITHM]()
    result=algo.run()
  2. Does the result variable in your code sample also contains optimal weights?
Marigold commented 2 years ago
  1. Yes, all algorithms have consistent interface and it's enough to call run() on them
  2. I guess you mean algorithm weights by "optimal weights"? If yes, then it can be accessed as result.B. Check out result.__dict__ for a dictionary of available attributes
shayandavoodii commented 2 years ago
  1. Yes, all algorithms have consistent interface and it's enough to call run() on them
  2. I guess you mean algorithm weights by "optimal weights"? If yes, then it can be accessed as result.B. Check out result.__dict__ for a dictionary of available attributes

I meant the weight of each stock which should be the output of the algorithm. But, what are the result.weights then?

Marigold commented 2 years ago

result.weights is a method that is run internally and returns B. What you're looking for is result.B.

algo.weights is a method that is run internally and returns B. It is then saved as result.B attribute which is identical to result.weights.

shayandavoodii commented 2 years ago

result.weights is a method that is run internally and returns B. What you're looking for is result.B.

Thanks! Just in case of curiosity, Do you mean, result.weights returns the same thing as result.B?

Marigold commented 2 years ago

Yes, it's exactly the same. Sorry, I thought you were talking about algo.weights(...) method. Updated my previous answer.

shayandavoodii commented 2 years ago

Yes, it's exactly the same. Sorry, I thought you were talking about algo.weights(...) method. Updated my previous answer.

Thanks a lot!