Skip to content

Add /optimize FastAPI endpoint with tests#33

Open
suyash469 wants to merge 2 commits intoGeomScale:mainfrom
suyash469:feat/api-optimize-endpoint
Open

Add /optimize FastAPI endpoint with tests#33
suyash469 wants to merge 2 commits intoGeomScale:mainfrom
suyash469:feat/api-optimize-endpoint

Conversation

@suyash469
Copy link

Summary

This PR adds a minimal FastAPI /optimize endpoint that runs a Least Squares index-replication optimization on MSCI data and returns optimized weights.

  • Adds /optimize in src/api.py:

    • Uses load_data_msci to load MSCI country and benchmark returns.
    • Sets LongOnly, fully-invested constraints with Constraints.
    • Builds OptimizationData(return_series, bm_series, align=True).
    • Runs a LeastSquares optimization and returns assets, weights, and sum_weights.
  • Adds tests:

    • test/tests_api.py:
      • Tests / and /optimize using TestClient, mocking load_data_msci and LeastSquares.
    • test/tests_data_loader.py:
      • Uses unittest.mock.patch on pd.read_csv, so the test no longer depends on local CSV files.

Testing

  • python -m unittest test.tests_data_loader test.tests_api

Related to: #26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant