##### The exercice is validated is all questions of the exercice are validated.
##### The exercise is validated if all questions of the exercise are validated.
##### Activate the virtual environment. If you used `conda` run `conda activate your_env`.
@ -8,7 +8,7 @@
###### Does it print `Python 3.x`? x >= 8
##### Does`import jupyter`, `import numpy` and `import pandas` run without any error?
###### Do `import jupyter`, `import numpy` and `import pandas` run without any error?
---
@ -16,9 +16,9 @@
#### Exercise 1: Series
##### The exercise is validated is all questions of the exercise are validated.
##### The exercise is validated if all questions of the exercise are validated.
##### The question 1 is validated if the output of is as below. The best solution uses `pd.date_range` to generate the index and `range` to generate the integer series.
###### For question 1, is the output as below? The best solution uses `pd.date_range` to generate the index and `range` to generate the integer series.
##### This question is validated if the output is as below. If the `NaN` values have been dropped the solution is also accepted. The solution uses `rolling().mean()`.
###### Is the output as below? If the `NaN` values have been dropped the solution is also accepted. The solution uses `rolling().mean()`.
```console
2010-01-01 NaN
@ -58,7 +58,7 @@
#### Exercise 2: Financial data
##### The exercise is validated is all questions of the exercise are validated.
##### The exercise is validated if all questions of the exercise are validated.
###### Have the missing values and data types been checked?
@ -68,9 +68,9 @@
###### Have `info` or/and `describe` been used to have a first look at the data?
##### The question 1 is validated if the right columns are inserted in `Candlestick``Plotly` object. The Candlestick is based on Open, High, Low and Close columns. The index is Date (datetime).
###### For question 1, are the right columns inserted in `Candlestick``Plotly` object? The Candlestick is based on Open, High, Low and Close columns. The index is Date (datetime).
##### This question 2 is validated if the output of `print(transformed_df.head().to_markdown())` is as below and if there are **482 months**.
###### For question 2, is the output of `print(transformed_df.head().to_markdown())` as below and are there **482 months**?
@ -85,7 +85,7 @@ To get this result there are two ways: `resample` and `groupby`. There are two k
- Find how to affect the aggregation on the last **business** day of each month. This is already implemented in Pandas and the keyword that should be used either in `resample` parameter or in `Grouper` is `BM`.
- Choose the right aggregation function for each variable. The prices (Open, Close and Adjusted Close) should be aggregated by taking the `mean`. Low should be aggregated by taking the `minimum` because it represents the lower price of the day, so the lowest price on the month is the lowest price of the lowest prices on the day. The same logic applied to High, leads to use the `maximum` to aggregate the High. Volume should be aggregated using the `sum` because the monthly volume is equal to the sum of daily volume over the month.
##### The question 3 is validated if it doesn't involve a for loop and the output is as below. The first way to do it is to compute the return without for loop is to use `pct_change`. And the second way to do it is to implement the formula given in the exercise in a vectorized way. To get the value at `t-1` the data has to be shifted with `shift`.
###### For question 3, does it not involve a for loop and is the output as below? The first way to do it is to compute the return without for loop is to use `pct_change`. And the second way to do it is to implement the formula given in the exercise in a vectorized way. To get the value at `t-1` the data has to be shifted with `shift`.
```console
Date
@ -109,7 +109,7 @@ To get this result there are two ways: `resample` and `groupby`. There are two k
#### Exercise 3: Multi asset returns
##### This question is validated if, without having used a for loop, the outputted DataFrame shape's `(261, 5)` and the output is the same as the one return with this line of code. The DataFrame contains random data. Make sure the output and the one returned by this code is based on the same DataFrame.
###### Is the outputted DataFrame's shape `(261, 5)` without having used a for loop and the is the output the same as the one returned with this line of code? The DataFrame contains random data. Make sure the output and the one returned by this code is based on the same DataFrame.
@ -121,7 +121,7 @@ To get this result there are two ways: `resample` and `groupby`. There are two k
#### Exercise 4: Backtest
##### The exercise is validated is all questions of the exercise are validated.
##### The exercise is validated if all questions of the exercise are validated.
###### Have the missing values and data types been checked?
@ -133,7 +133,7 @@ To get this result there are two ways: `resample` and `groupby`. There are two k
**My results can be reproduced using: `np.random.seed = 2712`. Given the versions of NumPy used I do not guaranty the reproducibility of the results - that is why I also explain the steps to get to the solution.**
##### The question 1 is validated if the return is computed as: Return(t) = (Price(t+1) - Price(t))/Price(t) and returns this output. Note that if the index is not ordered in ascending order the futur return computed is wrong. The answer is also accepted if the returns is computed as in the exercise 2 and then shifted in the futur using `shift`, but I do not recommend this implementation as it adds missing values!
###### For question 1, is the return computed as Return(t) = (Price(t+1) - Price(t))/Price(t) and returns the following output? Note that if the index is not ordered in ascending order the future return computed is wrong. The answer is also accepted if the returns is computed as in the exercise 2 and then shifted in the futur using `shift`, but I do not recommend this implementation as it adds missing values!
```console
Date
@ -160,9 +160,9 @@ An example of solution is:
compute_futur_return(df['Adj Close'])
```
##### The question 2 is validated if the index of the Series is the same as the index of the DataFrame. The data of the series can be generated using `np.random.randint(0,2,len(df.index)`.
###### For question 2, is the index of the Series the same as the index of the DataFrame? The data of the series can be generated using `np.random.randint(0,2,len(df.index)`.
##### This question is validated if the Pnl is computed as: signal \* futur_return. Both series should have the same index.
###### For question 3, is the Pnl computed as: signal \* futur_return? Both series should have the same index.
```console
Date
@ -180,6 +180,6 @@ An example of solution is:
Name: PnL, Length: 10119, dtype: float64
```
##### The question 4 is validated if the return of the strategy is computed as: `(Total earned - Total invested) / Total` invested. The result should be close to 0. The formula given could be simplified as `(PnLs.sum())/signal.sum()`. My return is: 0.00043546984088551553 because I invested 5147$ and I earned 5149$.
###### For question 4, is the return of the strategy computed as: `(Total earned - Total invested) / Total` invested? The result should be close to 0. The formula given could be simplified as `(PnLs.sum())/signal.sum()`. My return is: 0.00043546984088551553 because I invested 5147$ and I earned 5149$.
##### The question is validated if the previous signal Series is replaced with 1s. Similarly as the previous question, we earned 10128$ and we invested 10118$ which leads to a return of 0.00112670194140969 (0.1%).
###### For question 5, is the previous signal Series being replaced with 1s? Similarly as the previous question, we earned 10128$ and we invested 10118$ which leads to a return of 0.00112670194140969 (0.1%).