mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 13:01:38 +00:00
* Added basic openpyxl * Add screener checks to confirm that preset is correct (#580) * refactor screener finviz_view to view and model * Add checks for defined screener preset * Feature/fraud indicators (#581) * Fixed glitch reading AlphaVantage API key * Bug fix * Added mscore metric * Refactored code, added error handling * Updated reademe.md * Figuring out pre-commit * Figuring out pre-commit * Improved formating and code * Added Zscore * Formatted code Co-authored-by: Colin Delahunty <colindelahunty@Colins-Air.attlocal.net> * Reformated tests and started writing FA * Removed excel analytics * Figured out testing with input and print * Figured out testing with input and print * Added av_view tests * Added av_view tests * Added main_helper tests * Fixed Poetry * Added main helper tests * Expanded pycoingecko_view * Fixed ETF model * Added coinpaprika view tests * Added optimizer view tests * Updated tests Co-authored-by: Colin Delahunty <colindelahunty@Colins-Air.attlocal.net> Co-authored-by: DidierRLopes <dro.lopes@campus.fct.unl.pt> Co-authored-by: Colin Delahunty <colindelahunty@Colins-MacBook-Air.local>
74 lines
2.5 KiB
Python
74 lines
2.5 KiB
Python
from unittest import TestCase, mock
|
|
import sys
|
|
import io
|
|
|
|
from gamestonk_terminal.portfolio.portfolio_optimization import optimizer_view
|
|
|
|
|
|
class TestOptimizerView(TestCase):
|
|
def test_equal_weights(self):
|
|
capturedOutput = io.StringIO()
|
|
sys.stdout = capturedOutput
|
|
optimizer_view.equal_weight(["TSLA", "GME"], [])
|
|
sys.stdout = sys.__stdout__
|
|
capt = capturedOutput.getvalue()
|
|
self.assertIn("TSLA", capt)
|
|
|
|
def test_property_weighting(self):
|
|
capturedOutput = io.StringIO()
|
|
sys.stdout = capturedOutput
|
|
optimizer_view.property_weighting(["TSLA", "GME"], ["-p", "previousClose"])
|
|
sys.stdout = sys.__stdout__
|
|
capt = capturedOutput.getvalue()
|
|
self.assertIn("TSLA", capt)
|
|
|
|
def test_max_sharpe(self):
|
|
capturedOutput = io.StringIO()
|
|
sys.stdout = capturedOutput
|
|
optimizer_view.max_sharpe(["TSLA", "GME"], [])
|
|
sys.stdout = sys.__stdout__
|
|
capt = capturedOutput.getvalue()
|
|
self.assertIn("TSLA", capt)
|
|
|
|
def test_min_volatility(self):
|
|
capturedOutput = io.StringIO()
|
|
sys.stdout = capturedOutput
|
|
optimizer_view.min_volatility(["TSLA", "GME"], [])
|
|
sys.stdout = sys.__stdout__
|
|
capt = capturedOutput.getvalue()
|
|
self.assertIn("TSLA", capt)
|
|
|
|
def test_max_quadratic_utility(self):
|
|
capturedOutput = io.StringIO()
|
|
sys.stdout = capturedOutput
|
|
optimizer_view.max_quadratic_utility(["TSLA", "GME"], [])
|
|
sys.stdout = sys.__stdout__
|
|
capt = capturedOutput.getvalue()
|
|
self.assertIn("TSLA", capt)
|
|
|
|
def test_efficient_risk(self):
|
|
capturedOutput = io.StringIO()
|
|
sys.stdout = capturedOutput
|
|
optimizer_view.efficient_risk(["TSLA", "GME"], [])
|
|
sys.stdout = sys.__stdout__
|
|
capt = capturedOutput.getvalue()
|
|
self.assertIn("The minimum volatility", capt)
|
|
|
|
def test_efficient_return(self):
|
|
capturedOutput = io.StringIO()
|
|
sys.stdout = capturedOutput
|
|
optimizer_view.efficient_return(["TSLA", "GME"], [])
|
|
sys.stdout = sys.__stdout__
|
|
capt = capturedOutput.getvalue()
|
|
self.assertIn("TSLA", capt)
|
|
|
|
@mock.patch("matplotlib.pyplot.show")
|
|
def test_show_ef(self, mock_mlp):
|
|
# pylint: disable=unused-argument
|
|
capturedOutput = io.StringIO()
|
|
sys.stdout = capturedOutput
|
|
optimizer_view.show_ef(["TSLA", "GME"], [])
|
|
sys.stdout = sys.__stdout__
|
|
capt = capturedOutput.getvalue()
|
|
self.assertIn("\n", capt)
|