Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
1f3a143
Modified README
Jan 18, 2025
b8edd91
added assignement
Jan 18, 2025
d75e49d
modified README
Jan 18, 2025
e01b652
Added figure
Jan 18, 2025
bdb9835
Added folder
Jan 18, 2025
43207e2
Modified README
Jan 18, 2025
e11fc1a
modified README
Jan 18, 2025
243b947
Added datasets
Jan 25, 2025
a0c4b77
added functions.py
Jan 27, 2025
49b4a18
put functions in Code
Jan 27, 2025
50f6181
updated code
Jan 27, 2025
1a56148
Added report
Jan 30, 2025
3eebac6
Updated code
Feb 17, 2025
543bdc3
selector_function
Feb 18, 2025
767c398
selector_function
Feb 18, 2025
504f279
selector_function
Feb 18, 2025
e2e2d12
Mann Kendall function
Feb 18, 2025
95f49e7
mann kendall functions
Feb 18, 2025
b2b9eb3
mann kendall functions
Feb 18, 2025
663451d
updated introduction
Feb 18, 2025
a71c415
updated introduction
Feb 18, 2025
bdf0615
Creato con Colab
gpoccianti Feb 19, 2025
96bb48a
Creato con Colab
gpoccianti Feb 19, 2025
ac27ce0
Creato con Colab
gpoccianti Feb 19, 2025
a24990a
added image
Feb 19, 2025
8a6659d
try to reconcile branches
Feb 19, 2025
4cb0c6f
added changes
Feb 19, 2025
c969a92
added figures
Feb 19, 2025
b2340e9
added image
Feb 19, 2025
cdbf0d0
improved report
Feb 19, 2025
911bbca
updated readme
Feb 19, 2025
454261f
updated readme
Feb 19, 2025
29e5f78
added new version of the notebook
Feb 20, 2025
73a2f50
changed notebook
Feb 20, 2025
90f7d46
new markdown
Feb 20, 2025
8b14cda
modified Markdown
Feb 20, 2025
84e5170
new Figures
Feb 20, 2025
88133e2
updated Markdown
Feb 20, 2025
2d81a15
Updated Markdown
Feb 21, 2025
c9baedf
updated notebook
Feb 21, 2025
9efc7ba
modified markdown
Feb 21, 2025
2e37773
Small modification of Markdown
Feb 21, 2025
ef33375
Modified Markdown
Feb 21, 2025
20f8188
Modified Markdown
Feb 21, 2025
530d925
modified Markdown
Feb 21, 2025
0e84116
Fix Markdown formatting for mathematical expression
gpoccianti Nov 5, 2025
9c30563
Fix formatting for mathematical expression in README
gpoccianti Nov 5, 2025
e4b4844
Fix formatting of mathematical expression in README
gpoccianti Nov 5, 2025
0bb84e6
Fix LaTeX formatting in README.md
gpoccianti Nov 5, 2025
b5ad4c4
Fix LaTeX formatting in README.md
gpoccianti Nov 5, 2025
c0ea55a
Fix formatting issues in README.md
gpoccianti Nov 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Empty file added .Rhistory
Empty file.
Binary file added Code/.DS_Store
Binary file not shown.
Binary file added Code/Fig/.ipynb_checkpoints/trades-checkpoint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Code/Fig/GIF.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Code/Fig/Heatmap.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Code/Fig/Z-statistics.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Code/Fig/closing_prices_plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Code/Fig/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Code/Fig/mk.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Code/Fig/trades.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Code/Fig/trades2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3,572 changes: 3,572 additions & 0 deletions Code/XSOR_report_final.ipynb

Large diffs are not rendered by default.

Binary file added Code/__pycache__/functions.cpython-312.pyc
Binary file not shown.
Binary file added Code/__pycache__/functions1.cpython-312.pyc
Binary file not shown.
98,020 changes: 98,020 additions & 0 deletions Code/data_M15/.ipynb_checkpoints/DAX_M15_202005242300_202411131015-checkpoint.csv

Large diffs are not rendered by default.

97,551 changes: 97,551 additions & 0 deletions Code/data_M15/.ipynb_checkpoints/DJ_M15_202009240845_202411131015-checkpoint.csv

Large diffs are not rendered by default.

97,770 changes: 97,770 additions & 0 deletions Code/data_M15/.ipynb_checkpoints/SP500_M15_202009220000_202411131015-checkpoint.csv

Large diffs are not rendered by default.

98,020 changes: 98,020 additions & 0 deletions Code/data_M15/DAX_M15_202005242300_202411131015.csv

Large diffs are not rendered by default.

97,551 changes: 97,551 additions & 0 deletions Code/data_M15/DJ_M15_202009240845_202411131015.csv

Large diffs are not rendered by default.

98,850 changes: 98,850 additions & 0 deletions Code/data_M15/FTSE100_M15_201912230600_202411131015.csv

Large diffs are not rendered by default.

97,770 changes: 97,770 additions & 0 deletions Code/data_M15/SP500_M15_202009220000_202411131015.csv

Large diffs are not rendered by default.

833 changes: 833 additions & 0 deletions Code/functions.py

Large diffs are not rendered by default.

Binary file added Group Assignments 2025.pdf
Binary file not shown.
Binary file added Image/.DS_Store
Binary file not shown.
Binary file added Image/closing_prices_plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
96 changes: 87 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,95 @@
# Final Projects for Laboratory of Computational Physics

In each of the branches of this repo you find all the necessary to complete your final project.
In particular the file Project.ipynb describes the projects and provides guidance to its development.
Other files could be present if needed.
In each of the branches of this repo, you will find all the necessary materials to complete your final project. In particular, the file `Project.ipynb` describes the projects and provides guidance for their development. Other files may be present if needed.

Each branch is named after the group of students a given project is assigned to.
The groups compositions are listed [here](https://docs.google.com/spreadsheets/d/124iLKfGEpxT33WgRqtuJqsoAjADjbarMWn5xxClTYEw/edit?gid=1442920615#gid=1442920615)
Each branch is named after the group of students a given project is assigned to. The group compositions are listed [here](https://docs.google.com/spreadsheets/d/124iLKfGEpxT33WgRqtuJqsoAjADjbarMWn5xxClTYEw/edit?gid=1442920615#gid=1442920615).

Students are supposed to work together to produce a short report on the assigned task. The preferred format for the latter is a jupyter notebook, with the proper description, the code implemented for the purpose and the actual results (plots, tables, etc.). The notebook has to be delivered with all the cells executed and should live in a GitHib repository. There is no need to make a pull request to the central repository.
Students are expected to work together to produce a short report on the assigned task. The preferred format for the report is a Jupyter Notebook, containing the proper description, the implemented code, and the actual results (plots, tables, etc.). The notebook must be delivered with all cells executed and should reside in a GitHub repository. There is no need to make a pull request to the central repository.

### Computing Resources
## Computing Resources

A Virtual Machine within [CloudVeneto](http://cloudveneto.it/) can be created for each group. Note that, by default, they are not. For some projects though, large datasets are needed, in those cases a VM has been (are being) created to store those files. Refer to ClouldInstructions.md for the steps to take in order to use those resources.
A Virtual Machine within [CloudVeneto](http://cloudveneto.it/) can be created for each group. Note that, by default, they are not created. However, for some projects that require large datasets, a VM has been (or is being) created to store those files. Refer to `CloudInstructions.md` for the steps to use these resources.

Alternatively, students can use [colab](https://colab.research.google.com/) (for which though no instructions are provided here).
Alternatively, students can use [Google Colab](https://colab.research.google.com/) (though no instructions are provided here).

# Project Description
## Trending Asset into Mean Reverting Asset

Trending assets are those whose prices or returns display a sustained movement in one direction (upward or downward) over time. Such assets are typically non-stationary, meaning their statistical properties (e.g., mean, variance) evolve over time. This poses challenges for many standard financial analyses, which assume stationarity.

In this project, our task was to transform a trending financial asset into one that exhibits mean-reverting behavior through mathematical or statistical normalization techniques.

We based our analysis on two different techniques:

### 1) Fitting and Subtracting:

#### a) Mann-Kendall Test to Identify Trends

The Mann-Kendall (M-K) test is a non-parametric test used to assess monotonic trends. It is a hypothesis test:

- **H₀**: There is no monotonic trend in the data. The observations $x_1, x_2, ..., x_n$ are independent and randomly ordered over time.
- **Hₐ**: There is a monotonic trend in the data.

The test computes the difference between each pair of data points and counts how many of these differences are positive or negative, evaluating whether there are more increasing or decreasing values in the dataset.

When applied to a time series, the test statistic $S$ is defined as:

$$
S = \sum_{i=1}^{n-1} \sum_{j=i+1}^{n} \text{sgn} (x_j - x_i)
$$

where:

$$
\text{sgn} (x_j - x_i) =
\begin{cases}
+1 & \text{if } (x_j - x_i) > 0 \\
0 & \text{if }(x_j - x_i) = 0 \\
-1 & \text{if }(x_j - x_i) < 0
\end{cases}
$$

For $n \geq 10$, $S$ can be approximated by a normal distribution, allowing the use of a z-score:

$$
Z =
\begin{cases}
\frac{(S - 1)}{\sigma_s} & \text{if } S > 0 \\
0 & \text{if } S = 0 \\
\frac{(S + 1)}{\sigma_s} & \text{if } S < 0
\end{cases}
$$

where:

$$
\sigma_s = \sqrt{\frac{n(n-1)(2n+5) - \sum_{j=1}^{q} t_j (t_j - 1)(2t_j + 5)}{18}}
$$

Here, the first term in the numerator is the variance of $S$ assuming no ties, while the summation accounts for ties, reducing the variance. $q$ is the number of unique values that have ties, and $t_j$ is the count of occurrences for each tied value.

If $Z < Z_{\alpha/2}$ at a significance level $\alpha$, then no significant trend exists in the time series.

(References: [https://doi.org/10.2307/1907187](https://doi.org/10.2307/1907187), [doi:10.1017/S0020268100013019](doi:10.1017/S0020268100013019))

#### b) Linear Regression on Trending Regions

For the identified trending regions, we applied a linear regression and subtracted the corresponding fitted line to remove the trend component.

### 2) Rolling Mean:

#### a) Spectral Analysis to Determine Time Window

We analyzed the spectrum of the time series to identify a relevant frequency indicative of a trend. This frequency helped define a meaningful time window for further processing.

#### b) Rolling Average and Subtraction

We applied a rolling average with the determined time window and subtracted the resulting smoothed time series from the original data.

![An example of a trending asset](Image/closing_prices_plot.png "An example of a trending asset")

## Acknowledgments

This project was realized in collaboration with and under the supervision of [XSOR Capital](https://www.xsorcapital.com).

In particular, we thank **Nicole Zattarin** ([nicole.zattarin@xsorcapital.com](mailto:nicole.zattarin@xsorcapital.com)) for her guidance.
Loading