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

Chore/auto formatting workflow #109

Merged
merged 27 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2c321a7
Adding shell script to run black and isort and to commit changes if p…
fmilthaler Jul 22, 2023
88ef259
editing requirements
fmilthaler Jul 22, 2023
af23ea0
edit setup
fmilthaler Jul 22, 2023
42c93dd
adding workflow without push
fmilthaler Jul 22, 2023
3e96b53
fixing workflow
fmilthaler Jul 22, 2023
6e2293e
test print github.ref
fmilthaler Jul 22, 2023
fdd7fa3
print git branch
fmilthaler Jul 22, 2023
fa6135c
another test
fmilthaler Jul 22, 2023
0187ce5
test to push changes to the (PR) branch
fmilthaler Jul 22, 2023
c3cae13
test github.ref
fmilthaler Jul 22, 2023
30bbf83
fixing workflow
fmilthaler Jul 22, 2023
92ca47c
test
fmilthaler Jul 22, 2023
bfe1d2b
merging both scripts to update readmes
fmilthaler Jul 22, 2023
918a547
renaming script to update readme
fmilthaler Jul 22, 2023
5b9463f
updating script
fmilthaler Jul 22, 2023
9d9276b
adding new script to commit changes (if present), and removing that c…
fmilthaler Jul 22, 2023
3ca21a8
fixing workflow and script
fmilthaler Jul 22, 2023
b9381c2
fixing scripts and workflow again
fmilthaler Jul 22, 2023
4667c11
Echo appropriate message when executing auto-commit.sh
fmilthaler Jul 22, 2023
d9074f8
updating scripts
fmilthaler Jul 22, 2023
0e741b8
minor changes and reverting test changes
fmilthaler Jul 22, 2023
e7379a4
only run new workflow when pushed to master or develop
fmilthaler Jul 22, 2023
2788879
New feature: Value at Risk (VaR) (#106)
PietropaoloFrisoni Jul 23, 2023
101ee7f
Updating README files (#110)
fmilthaler Jul 23, 2023
197624e
Merge branch 'master' into chore/auto-formatting-workflow
fmilthaler Jul 24, 2023
a4dc9ee
enabling auto-format on PRs
fmilthaler Jul 24, 2023
5a6ad6e
Automated formatting changes
github-actions[bot] Jul 24, 2023
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
49 changes: 49 additions & 0 deletions .github/workflows/auto-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: AutoUpdateFormatting
on:
push:
branches:
- master
- develop
pull_request:
branches:
- master
- develop

jobs:
code-formatting:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10' # Specify the desired Python version

- name: Install dependencies
run: |
pip install -r requirements_test.txt

- name: Updating README files
id: update_readme
run: |
bash scripts/update-readme.sh
bash scripts/auto-commit.sh "Updating README files"
continue-on-error: true

- name: Code formatting and committing changes
id: code_format
run: |
bash scripts/auto-format.sh
bash scripts/auto-commit.sh "Automated formatting changes"
continue-on-error: true

- name: Push changes
if: ${{ steps.update_readme.outcome == 'success' || steps.code_format.outcome == 'success' }}
uses: ad-m/github-push-action@master
with:
branch: ${{ github.head_ref }}
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,3 @@ Furthermore, it is also shown how the entire *Efficient Frontier* and the optima
Also, the optimisation of a portfolio and its visualisation based on a *Monte Carlo* is shown.

Finally, *FinQuant*'s visualisation methods allow for overlays, if this is desired. Thus, with only the following few lines of code, one can create an overlay of the *Monte Carlo* run, the *Efficient Frontier*, its optimised portfolios for *Minimum Volatility* and *Maximum Sharpe Ratio*, as well as the portfolio's individual stocks.

3 changes: 2 additions & 1 deletion example/Example-Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

# <codecell>

import datetime
import pathlib

import matplotlib.pyplot as plt
import pandas as pd
import datetime

# importing FinQuant's function to automatically build the portfolio
from finquant.portfolio import build_portfolio
Expand Down
3 changes: 2 additions & 1 deletion example/Example-Build-Portfolio-from-file.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

# <codecell>

import datetime
import pathlib

import pandas as pd
import datetime

# importing FinQuant's function to automatically build the portfolio
from finquant.portfolio import build_portfolio
Expand Down
3 changes: 2 additions & 1 deletion example/Example-Build-Portfolio-from-web.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

# <codecell>

import pandas as pd
import datetime

import pandas as pd

# importing some custom functions/objects
from finquant.portfolio import build_portfolio

Expand Down
3 changes: 2 additions & 1 deletion example/Example-Optimisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@

# <codecell>

import datetime
import pathlib

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import datetime

# importing FinQuant's function to automatically build the portfolio
from finquant.portfolio import build_portfolio
Expand Down
6 changes: 4 additions & 2 deletions finquant/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ class Asset:

"""

def __init__(self, data: pd.Series, name: str, asset_type: str = 'Market index') -> None:
def __init__(
self, data: pd.Series, name: str, asset_type: str = "Market index"
) -> None:
"""
:Input:
:data: ``pandas.Series``, of asset prices
Expand Down Expand Up @@ -119,4 +121,4 @@ def properties(self):
def __str__(self):
# print short description
string = f"Contains information about {self.asset_type}: {self.name}."
return string
return string
3 changes: 2 additions & 1 deletion finquant/market.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import numpy as np
import pandas as pd

from finquant.asset import Asset
from finquant.returns import daily_returns, historical_mean_return

Expand Down Expand Up @@ -43,4 +44,4 @@ def comp_daily_returns(self) -> pd.Series:
"""Computes the daily returns (percentage change) of the market index.
See ``finquant.returns.daily_returns``.
"""
return daily_returns(self.data)
return daily_returns(self.data)
2 changes: 1 addition & 1 deletion finquant/portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
- Individual stocks of the portfolio (Expected Return over Volatility)
"""

from typing import List
import datetime
from typing import List

import matplotlib.pylab as plt
import numpy as np
Expand Down
1 change: 1 addition & 0 deletions finquant/stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import numpy as np
import pandas as pd

from finquant.asset import Asset
from finquant.returns import daily_returns, historical_mean_return

Expand Down
2 changes: 1 addition & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
black==23.1.0
black
mypy
isort
jupyter
Expand Down
3 changes: 3 additions & 0 deletions requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
pytest>=7.3.2
black
mypy
isort
pylint
25 changes: 25 additions & 0 deletions scripts/auto-commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

echo "Running auto commit"

COMMITMSG=$1

if [ -z "$COMMITMSG" ]; then
COMMITMSG="Automated formatting changes"
fi

# Stage changes
git add --update

# Check Git diff-index
git diff-index --quiet HEAD --

if [ $? -eq 0 ]; then
echo "No changes found, nothing to see/do here."
exit 1
else
echo "Changes found. Preparing commit."
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -m "${COMMITMSG}"
fi
6 changes: 6 additions & 0 deletions scripts/auto-format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# Code formatting with isort and black
echo "Code formatting with isort and black:"
isort $(git ls-files '*.py')
black $(git ls-files '*.py')
43 changes: 43 additions & 0 deletions scripts/update-readme.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

update_version_readme() {
local version_file="version"
local readme_md="$1"

# Read the current version from the "version" file
local current_version=$(grep -Eo 'version=([0-9]+\.){2}[0-9]+' "$version_file" | cut -d'=' -f2)

update_file() {
local file=$1
sed -i "s/pypi-v[0-9]\+\.[0-9]\+\.[0-9]\+/pypi-v$current_version/" "$file"
echo "Version updated to $current_version in $file"
}

# Update version in README.md
update_file "$readme_md"
}

update_readme_tex() {
local file_path="$1"

# Copy README.md to README.tex.md
cp README.md "$file_path"

# Read the contents of README.tex.md
local content=$(<"$file_path")

# Replace patterns
content=$(echo "$content" | sed -E "s/<img src=\"(.*?)\" align=middle width=194.52263655pt height=46.976899200000005pt\/>/\$\\\\displaystyle\\\\dfrac{\\\\text{price}_{t_i} - \\\\text{price}_{t_0} + \\\\text{dividend}}{\\\\text{price}_{t_0}}\$/")

content=$(echo "$content" | sed -E "s/<img src=\"(.*?)\" align=middle width=126.07712039999997pt height=48.84266309999997pt\/>/\$\\\\displaystyle\\\\dfrac{\\\\text{price}_{t_i} - \\\\text{price}_{t_{i-1}}}{\\\\text{price}_{t_{i-1}}}\$/")

content=$(echo "$content" | sed -E "s/<img src=\"(.*?)\" align=middle width=208.3327686pt height=57.53473439999999pt\/>/\$\\\\displaystyle\\\\log\\\\left(1 + \\\\dfrac{\\\\text{price}_{t_i} - \\\\text{price}_{t_{i-1}}}{\\\\text{price}_{t_{i-1}}}\\\\right)\$/")

# Write the updated contents back to README.tex.md
echo "$content" > "$file_path"
}

# Update both readme files:
echo "Updating README files:"
update_version_readme "README.md"
update_readme_tex "README.tex.md"
27 changes: 0 additions & 27 deletions scripts/update_readme.tex.md.sh

This file was deleted.

21 changes: 0 additions & 21 deletions scripts/update_version_readme.sh

This file was deleted.

4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ def read_requirements(file_path):
install_requires = read_requirements("requirements.txt")

extras_require = {
"test": read_requirements("requirements_test.txt"),
"cd": read_requirements("requirements_cd.txt"),
"dev": read_requirements("requirements_dev.txt"),
"docs": read_requirements("requirements_docs.txt"),
"cd": read_requirements("requirements_cd.txt"),
"test": read_requirements("requirements_test.txt"),
}

setuptools.setup(
Expand Down