Skip to content

merge dev #4

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

Draft
wants to merge 7 commits into
base: devel
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
/*.idea
*/.idea
*.pro.*
*.vscode

#Build
/build
/cmake-build-debug
/cmake*
Makefile
*stash*
.env

#Library

Expand All @@ -19,3 +21,4 @@ Makefile



/.vscode/
44 changes: 16 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@ message(status "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
if(MSVS)
add_compile_options( /wd4127 /wd4250)
else()
add_compile_options(-Wall -Wextra -Wno-unused-function ) #-Werror
add_compile_options(-Wall -Wextra -Wno-unused-function) #-Werror -Wpedantic
endif()


if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g")
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -DNDEBUG")
endif()

add_subdirectory(lib/common)

#find Package
find_package(Qt5 COMPONENTS Widgets Network Core Gui Charts REQUIRED)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Network Core Gui Multimedia Charts)

find_package(Threads REQUIRED)

#for QT
Expand All @@ -25,12 +34,11 @@ set(CMAKE_AUTOMOC ON)
#set(CMAKE_AUTORCC ON)

#Standart
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS -pthread)


#Version
set(VERSION_MAJOR 0)
set(VERSION_MINOR 2)
Expand All @@ -51,30 +59,12 @@ set(CMAKE_AUTOUIC_SEARCH_PATHS ${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/common/)

#file( GLOB_RECURSE SOURCE_FILES *.cpp)
#file( GLOB_RECURSE HEADER_FILES *.h)
file( GLOB_RECURSE SOURCE_FILES common/*.cpp Model/acsmodel.cpp main.cpp)
file( GLOB_RECURSE HEADER_FILES common/*.h Model/acsmodel.h)

#file( GLOB_RECURSE MODEL_FILES Model/*.cpp)
#file( GLOB_RECURSE API_FILES Model/*.h)

SET( SOURCE_FILES
Model/acsmodel.cpp
common/mainwindow.cpp
common/avgcoststocks.cpp
common/chart.cpp
common/csvmodel.cpp
common/tradelog.cpp
main.cpp)
SET( HEADER_FILES
Model/acsmodel.h
common/mainwindow.h
common/avgcoststocks.h
common/chart.h
common/threadpool.h
common/timer.h
common/csvreader.h
common/csvmodel.h
common/tradelog.h)

#file(GLOB CLIENT_FILE *.cpp *.h)

set(UIFORM common/mainwindow.ui)
Expand All @@ -83,12 +73,10 @@ set(UIFORM common/mainwindow.ui)
QT5_WRAP_UI(UI_HEADERS ${UIFORM} )

add_executable(${PROJECT_NAME} ${HEADER_FILES} ${SOURCE_FILES} ${UI_HEADERS})
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Widgets Qt5::Network Qt5::Core Qt5::Gui Qt5::Charts Threads::Threads stdc++fs lib::common)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Charts Threads::Threads stdc++fs lib::common)

install (TARGETS ${PROJECT_NAME} DESTINATION bin)

#SET(CPACK_PACKAGE_VERSION "1.0.2")

set(CPACK_SYSTEM_NAME ${SO_VERSION})

#Generate debian package with cpack [or alternative make package]
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Service Stock Markets
The service for calculate some parameters stock market
## Requirements
<br>-C++17 compiler support
<br>-C++20 compiler support
<br>-Cmake
<br>-QT
<br>-Doxygen
Expand All @@ -12,19 +12,19 @@ git clone https://github.com/silverstringer/ssm.git
mkdir build && cd build

cmake ..

make -j8
make -j12

## Install
make install

## Run


## Usage
1) Simple Dollar Cost Average Digital Asset( on bull market)
2) Different percentage on month
3) Calculate average price of asset
4) Futures calc
5) Invest calc

*Advanced. Save resultDCA on *.csv file, build graph

Expand Down
12 changes: 8 additions & 4 deletions common/chart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ void Graph::buildBarChartDiffDepo(const std::map<QString,int> &data)
for (auto&& [key, value] : data) {
set[i] = new QBarSet(key);
*set[i] <<depo<<value;
// *set[i] <<0<<3<<4<<8<<45<<90<<123<<450 <<600<<900<<0<<0;
// *set[i] <<m_depo<<value<<0<<0<<0<<0<<0<<0<<0<<0<<0<<0;
series->append(set[i]);
i++;
}
Expand All @@ -98,7 +96,7 @@ void Graph::buildBarChartDiffDepo(const std::map<QString,int> &data)
series->attachAxis(axisX);

QValueAxis *axisY = new QValueAxis();
auto param = min_max_range_element(data);
[[maybe_unused]]auto param = min_max_range_element(data);

// axisY->setRange(0, max->second + min->second);
// axisY->setTickCount(data.size() * 1.5);
Expand All @@ -117,8 +115,14 @@ void Graph::buildLineChart(const std::map<int,int> &data) {

QLineSeries *series = new QLineSeries();

QVector<QPointF> points;

for (auto&& [key, value] : data)
series->append(key,value);
points.append(QPointF(key, value));
series->replace(points);

// for (auto&& [key, value] : data)
// series->append(key,value);

QChart *chart = new QChart();
chart->legend()->hide();
Expand Down
114 changes: 90 additions & 24 deletions common/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
#include <QShortcut>
#include <QMap>

#include <QFuture>
#include <QtConcurrent/qtconcurrentrun.h>
#include <QFutureWatcher>


#include <iostream>


Expand Down Expand Up @@ -70,8 +75,66 @@ MainWindow::MainWindow(QWidget *parent) :
ui->spnGoalPrice->setValue(ui->spnFirstPrice->value());
});

connect(ui->btnFuturesCalc, &QPushButton::clicked, []() {

try {
QtConcurrent::run([]() {
FuturesCalculator calc;
calc.run();
});
}
catch(std::exception& e){
qDebug() <<e.what();
}
});

connect(ui->btnInvestmentCalc, &QPushButton::clicked, []() {

try {
QtConcurrent::run([]() {

int currentLots;
double currentAvgPrice, targetAvgPrice, budget;

std::cout << "\n Введите текущее количество лотов: ";
std::cin >> currentLots;
std::cout << "Введите текущую среднюю цену (руб.): ";
std::cin >> currentAvgPrice;
std::cout << "Введите целевую среднюю цену (руб.): ";
std::cin >> targetAvgPrice;
std::cout << "Введите бюджет (руб., или 0 для неограниченного): ";
std::cin >> budget;
budget = (budget <= 0) ? std::numeric_limits<double>::max() : budget;

InvestmentCalculator::compareStrategies(currentLots, currentAvgPrice, targetAvgPrice, budget);

});
}
catch(std::exception& e){
qDebug() <<e.what();
}
});

connect(ui->btnCalculateDCA, &QPushButton::clicked, [this]() {
calculateDCA();

QFuture <void > future = QtConcurrent::run(this, &MainWindow::calculateDCA);
QFutureWatcher <void> * watcher_calculate = new QFutureWatcher <void >(this);
connect(watcher_calculate, &QFutureWatcher<void>::finished,this,[&](){
emit calcDone();
ui->btnCalculateDCA->setText("calculate");

// ui->spnGoalPrice->setStyleSheet("QDoubleSpinBox {color : red;}");
//
// ui->spnRangeAsset->setStyleSheet("QDoubleSpinBox {color : green; }");
// ui->spnRangePrice->setStyleSheet("QDoubleSpinBox {color : green; }");
//
// ui->lblRangeSum->setStyleSheet("QLabel {color : green; }");
});
watcher_calculate->setFuture(future);
ui->btnCalculateDCA->setText("calculate...");


// calculateDCA();
});
}

Expand Down Expand Up @@ -263,26 +326,7 @@ void MainWindow::calculate(dca &res, int max_range) {
}

//set GUI
ui->lblTotalFirstSum->setText(QString::number(res.assets * res.price));

for (const auto value:res.goal_range) {
auto range_assets = value.first;
auto range_price = value.second;

ui->spnRangeAsset->setValue(range_assets);
ui->spnRangePrice->setValue(range_price);

ui->spnTotalAsset->setValue(range_assets + res.assets);
ui->lblTotalSum->setText(QString::number(range_price * range_assets + res.assets * res.price));

ui->spnGoalPrice->setStyleSheet("QDoubleSpinBox {color : red;}");

ui->spnRangeAsset->setStyleSheet("QDoubleSpinBox {color : green; }");
ui->spnRangePrice->setStyleSheet("QDoubleSpinBox {color : green; }");

ui->lblRangeSum->setText(QString::number(range_assets * range_price));
ui->lblRangeSum->setStyleSheet("QLabel {color : green; }");
}
setGuiCalculateDca(res);

// emit calcDone();
}
Expand Down Expand Up @@ -434,12 +478,12 @@ void MainWindow::getDiffPercentDetails() {
}

std::unique_ptr<Graph> graph = std::make_unique<Graph>();
graph->setType(Graph::TypeChart::BarChart);
graph->setType(Graph::TypeChart::LineChart);
graph->setTitleGraph("Diff Percentage", "Month", "Depo");

graph->buildBarChart(data_convert);
// graph->buildBarChart(data_convert);
// graph->buildBarChartDiffDepo(data_convert);
// graph->buildLineChart(data_convert1);
graph->buildLineChart(data_convert1);

//View csv data from file
char delim = ';';
Expand Down Expand Up @@ -520,4 +564,26 @@ void MainWindow::setBackgroundMainWindow() {

}

void MainWindow::setGuiCalculateDca(dca &res) {

ui->lblTotalFirstSum->setText(QString::number(res.assets * res.price));

for (const auto value:res.goal_range) {
auto range_assets = value.first;
auto range_price = value.second;

ui->spnRangeAsset->setValue(range_assets);
ui->spnRangePrice->setValue(range_price);

ui->spnTotalAsset->setValue(range_assets + res.assets);
ui->lblTotalSum->setText(QString::number(range_price * range_assets + res.assets * res.price));
//
// ui->spnGoalPrice->setStyleSheet("QDoubleSpinBox {color : red;}");
//
// ui->spnRangeAsset->setStyleSheet("QDoubleSpinBox {color : green; }");
// ui->spnRangePrice->setStyleSheet("QDoubleSpinBox {color : green; }");
//
ui->lblRangeSum->setText(QString::number(range_assets * range_price));
// ui->lblRangeSum->setStyleSheet("QLabel {color : green; }");
}
}
5 changes: 5 additions & 0 deletions common/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#include "chart.h"
#include "csvreader.h"
#include "csvmodel.h"
#include "futurescalculator.h"
#include "investmentcalculator.h"

#include "storage.h"

#include <QMainWindow>
#include <QDebug>
Expand Down Expand Up @@ -51,6 +55,7 @@ class MainWindow : public QMainWindow
void calculateDiffPercentage();
void setHotKey();
void setBackgroundMainWindow();
void setGuiCalculateDca(dca &res);
private:
bool isMoonTheme { false };
std::map<double, double> resultDiffPercent;
Expand Down
28 changes: 27 additions & 1 deletion common/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>560</width>
<width>582</width>
<height>410</height>
</rect>
</property>
Expand Down Expand Up @@ -478,6 +478,32 @@
<string>Trade log</string>
</property>
</widget>
<widget class="QPushButton" name="btnFuturesCalc">
<property name="geometry">
<rect>
<x>390</x>
<y>340</y>
<width>91</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>FuturesCalc</string>
</property>
</widget>
<widget class="QPushButton" name="btnInvestmentCalc">
<property name="geometry">
<rect>
<x>490</x>
<y>300</y>
<width>81</width>
<height>71</height>
</rect>
</property>
<property name="text">
<string>Invest Calc</string>
</property>
</widget>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
Expand Down
9 changes: 9 additions & 0 deletions common/tradelog.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
#include "tradelog.h"

AnalyzeTradeLogSummary::AnalyzeTradeLogSummary( [[maybe_unused]]TradeLogSummary &log) {

}

void AnalyzeTradeLogSummary::calculate() {


}
Loading