Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
36 changes: 36 additions & 0 deletions .github/workflows/build-wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Build Wheels

on:
push:
branches: [ main, pip_test_2 ]
pull_request:
branches: [ main ]

jobs:
build_wheels:
strategy:
matrix:
os: [ ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Check out code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Install cibuildwheel
run: pip install cibuildwheel

- name: Build wheels
run: cibuildwheel --output-dir dist .

- name: Upload wheels artifact
uses: actions/upload-artifact@v4 # Updated to v4
with:
name: wheels-${{ matrix.os }} # Creates an artifact named e.g., "wheels-ubuntu-latest"
path: dist/*.whl # Uploads all .whl files from the 'dist' directory
if-no-files-found: error # Optional: Fails the step if no wheels are found

58 changes: 47 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 3.15)

project(finmath)
project(finmath LANGUAGES CXX)

# Set the C++ standard
set(CMAKE_CXX_STANDARD 17)
Expand All @@ -12,19 +12,17 @@ set(CMAKE_BUILD_TYPE Release)
# Add include directories
include_directories(${PROJECT_SOURCE_DIR}/include)

# For MSVC, define _USE_MATH_DEFINES to get M_PI etc. from <cmath>
if(MSVC)
add_compile_definitions(_USE_MATH_DEFINES)
message(STATUS "MSVC detected, adding _USE_MATH_DEFINES compile definition.")
endif()

# Source files
file(GLOB SOURCES "src/cpp/*/*.cpp")

# Create the main C++ library target with a unique name
add_library(finmath_library SHARED ${SOURCES}
"src/cpp/InterestAndAnnuities/simple_interest.cpp"
"include/finmath/InterestAndAnnuities/simple_interest.h"
"include/finmath/OptionPricing/options_pricing.h"
"include/finmath/OptionPricing/options_pricing_types.h"
"include/finmath/TimeSeries/rolling_volatility.h"
"include/finmath/TimeSeries/simple_moving_average.h"
"include/finmath/TimeSeries/rsi.h"
"include/finmath/TimeSeries/ema.h")
add_library(finmath_library SHARED ${SOURCES})

# Test executables
add_executable(black_scholes_test test/OptionPricing/black_scholes_test.cpp)
Expand Down Expand Up @@ -81,3 +79,41 @@ set_target_properties(finmath_bindings PROPERTIES OUTPUT_NAME "finmath")

# Link the Python bindings target with the C++ library
target_link_libraries(finmath_bindings PRIVATE finmath_library)

# Set install target for pip to find shared lib
install(TARGETS finmath_bindings finmath_library
LIBRARY DESTINATION finmath
ARCHIVE DESTINATION finmath
RUNTIME DESTINATION finmath
)

if(APPLE)
# For the Python bindings module
set_target_properties(finmath_bindings PROPERTIES
BUILD_WITH_INSTALL_RPATH TRUE
INSTALL_RPATH "@loader_path"
)
# For the library itself (if needed)
set_target_properties(finmath_library PROPERTIES
BUILD_WITH_INSTALL_RPATH TRUE
INSTALL_RPATH "@loader_path"
)
elseif(UNIX) # Linux
# $ORIGIN tells the dynamic linker to look for the library
# in the same directory as the binary (finmath_bindings module).
# auditwheel will usually refine this.
set_target_properties(finmath_bindings PROPERTIES
BUILD_RPATH "$ORIGIN"
)
set_target_properties(finmath_bindings PROPERTIES
INSTALL_RPATH "$ORIGIN"
)
set_target_properties(finmath_library PROPERTIES
INSTALL_RPATH "$ORIGIN"
)
set(_INSTALL_RPATH "$ORIGIN")
else() # Windows or other OS where RPATH is not standard
set(_INSTALL_RPATH "")
endif()

message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
5 changes: 5 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include CMakeLists.txt
recursive-include include *.h
recursive-include src/cpp *.cpp
recursive-include test *.cpp
recursive-exclude test-env *
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
- C++17 or later
- Python 3.6 or later
- `pybind11` (for Python bindings)
- `CMake` 3.10 or later (for building the library)
- `CMake` 3.5 or later (for building the library)
- `ninja` For optimizing cmake build

### Build Instructions

Expand Down
424 changes: 0 additions & 424 deletions cmake-build-debug/build.ninja

This file was deleted.

18 changes: 18 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[build-system]
requires = ["scikit-build-core>=0.10", "pybind11==2.10.0"]
build-backend = "scikit_build_core.build"

[project]
name = "finmath"
version = "0.1.16"
description = "A financial math library"
readme = { file = "README.md", content-type = "text/markdown" }

requires-python = ">=3.9"
dependencies = [
"pybind11==2.10.0"
]

[tool.scikit-build]
build-dir = "build"
cmake.args = ["-DCMAKE_POLICY_VERSION_MINIMUM=3.5"]
9 changes: 9 additions & 0 deletions scripts/test_binds
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cd ..
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/local -DCMAKE_OSX_ARCHITECTURES=arm64 -DCMAKE_BUILD_TYPE=Release
make
make install
export PYTHONPATH=$HOME/local:$PYTHONPATH
python3 -c "import finmath; print(finmath.compound_interest(1000, 5, 10, 4))"
cd ..
rm -rf build
1 change: 1 addition & 0 deletions src/finmath/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .finmath import *
Loading