小编Cri*_*ngo的帖子

如何在 Python 中使用 Returns 计算 MaximumDrawdown

我有 DataFramefinal与我的投资组合的回报。我正在尝试使用回报来计算 MaxDrawdown。我已经尝试了下面的代码,确实看到了很多 stackexchange 问题。但无法解决这个问题。有没有办法使用投资组合的回报来计算最大回撤。

              Returns
1/2/2009     0.030483579
1/5/2009     0.002872092
1/6/2009     0.01461333
1/7/2009    -0.032431836
1/8/2009     0.0055774
1/9/2009    -0.019844336
1/12/2009   -0.019705618
1/13/2009    0.001093185
1/14/2009   -0.032726765
1/15/2009    0.013635182
1/16/2009    0.009807648
1/20/2009   -0.044440252
1/21/2009    0.035156229
1/22/2009   -0.01460641
1/23/2009    0.007399468
1/26/2009    0.007910521
1/27/2009    0.007848472
1/28/2009    0.028944903
1/29/2009   -0.023816962
1/30/2009   -0.02550717
2/2/2009    -0.000292223
2/3/2009     0.020191091
2/4/2009    -7.93651E-06
2/5/2009     0.020070065
2/6/2009     0.026235957
2/9/2009    -0.001606124
2/10/2009   -0.03629415
2/11/2009    0.00248416
2/12/2009    0.001925152
2/13/2009   -0.00441840
Run Code Online (Sandbox Code Playgroud)

代码:

cum_returns = (1 + final).cumprod()
drawdown =  1 - final.div(final.cummax())
Run Code Online (Sandbox Code Playgroud)

谁能帮我解决这个问题。谢谢!

python finance quantitative-finance pandas

2
推荐指数
1
解决办法
4988
查看次数

过滤后如何处理负像素值?

我有一个8位图像,我想用一个矩阵对它进行过滤以进行边缘检测。我的内核矩阵是

0  1  0
1 -4  1
0  1  0
Run Code Online (Sandbox Code Playgroud)

对于某些指数,它给了我负值。我应该和他们一起做什么?

image-processing convolution edge-detection imagefilter

2
推荐指数
1
解决办法
1365
查看次数

匿名函数的导数,而不在Matlab中定义符号变量

请考虑以下代码:

f = @(x) x.^2; 
Run Code Online (Sandbox Code Playgroud)

是否有可能将函数句柄的导数f作为另一个函数句柄,而不定义符号变量?

matlab anonymous-function derivative function-handle

2
推荐指数
1
解决办法
113
查看次数

面对地标和使用光流稳定

我在窗口露脸和一些特殊点时编写程序(68)。我使用Haar Casscade和FaceLandmarkLBF。我的程序有问题。当脸部位置稳定时,脸部点会抖动(抖动)。我该如何解决?谢谢。

#include <iostream>

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/objdetect/objdetect.hpp>

#include <opencv2/face.hpp>

using cv::Scalar;
using cv::Point;

int main(int argc, char** argv)
{
    cv::CascadeClassifier faceDetector("haarcascade_frontalface_alt2.xml");

    cv::Ptr<cv::face::Facemark>facemark = cv::face::FacemarkLBF::create();

    facemark->loadModel("lbfmodel.yaml");

    cv::VideoCapture vc(0);

    while (true)
    {
        cv::Mat frame, gray;

        vc.read(frame);

        cv::cvtColor(frame, gray, cv::COLOR_BGR2GRAY);
        //
        std::vector<cv::Rect> faces;

        faceDetector.detectMultiScale(gray, faces);

        std::vector< std::vector<cv::Point2f> > landmarks;

        bool success = facemark->fit(frame, faces, landmarks);
        for (size_t i = 0; i < landmarks.size(); i++)
        {
            for (size_t j = 0; j < landmarks[i].size(); j++)
            {
                cv::circle(frame, cv::Point(landmarks[i][j].x, landmarks[i][j].y), 2, Scalar(255, …
Run Code Online (Sandbox Code Playgroud)

c++ opencv computer-vision

2
推荐指数
1
解决办法
984
查看次数

Condense a set of points of a polygon into a shorter set of points

I have the following polygon which is just a set of 2D points as follows:-

poly0=[80    60
    90    60
   100    60
   110    60
   110    50
   120    50
   130    50
   140    50
   150    50
   160    50
   170    50
   180    50
   190    50
   200    50
   210    50
   210    60
   210    70
   210    80
   210    90
   220    90
   220   100
   210   100
   210   110
   200   110
   200   120
   190   120
   180   120
   180   130
   170   130
   160   130
   150   130
   140   130
   130 …
Run Code Online (Sandbox Code Playgroud)

matlab polygon

2
推荐指数
1
解决办法
88
查看次数

基于超像素的图像边界

可以使用适当的索引手动指定位于图像边界的超像素(例如下面的示例用于第二个超像素L==2):

分割图像

选定的超像素

在某些情况下,需要以系统且非手动的方式指定位于图像边界中的所有那些超像素,类似于下面的图像:

没有边缘超像素的超像素图像

有什么标准方法可以做到吗?

matlab image-processing boundary image-segmentation superpixels

2
推荐指数
1
解决办法
73
查看次数

匿名函数中的if-then-else

我试图在匿名函数中使用某种if-then-else语句,该函数本身是的一部分cellfun。我有一个包含多个双矩阵的单元格数组。我想用+1替换所有双精度矩阵中的所有正数,并用-1替换所有负数。我想知道我是否可以使用匿名函数而不是编写一个单独的函数,然后再从中调用它cellfun

这是玩具示例:

mat = [2, 2, 0, -2; -2, 0, 0, 2; -2, 2, -2, 2]
cellarray = repmat({mat}, 3, 1)
Run Code Online (Sandbox Code Playgroud)

我正在寻找这样的东西:

new_cellarray = cellfun(@(x) if x > 0 then x = 1 elseif x < 0 then x = -1, cellarray, 'UniformOutput', false)
Run Code Online (Sandbox Code Playgroud)

我也尝试过此操作,但是,显然不允许我在匿名函数中添加等号。

new_cellarray = cellfun(@(x) x(x > 0) = 1, cellarray, 'UniformOutput', false)
new_cellarray = cellfun(@(x) x(x < 0) = -1, cellarray, 'UniformOutput', false)
Run Code Online (Sandbox Code Playgroud)

matlab anonymous-function cell-array

2
推荐指数
1
解决办法
62
查看次数

Delete all empty cells in a cell array

I have an array of cells in which I want to select 3 lines so I used this temp = testresults(13:15,1:end).

The array being bigger, I get a lot of empty cells

{'Summary Test Re…'}    {'Overall'   }    {0×0 char          }    {'OVP Transition …'}    {0×0 char}    {0×0 char}    {0×0 char}    {0×0 char}    {0×0 char}    {0×0 char}
{'Pass/Fail'       }    {'Passed'    }    {'No Transition t…'}    {'Passed'          }    {0×0 char}    {0×0 char}    {0×0 char}    {0×0 char}    {0×0 char}    {0×0 char}
{'Failed cases'    } …
Run Code Online (Sandbox Code Playgroud)

arrays matlab cell-array

2
推荐指数
1
解决办法
62
查看次数

如何防止图例在 R2017a 及更高版本中更新?

自 MATLAB R2017a 起,当向坐标区添加绘图时,图例图例会自动更新。以前,人们可以这样做:

data = randn(100,4);
plot(data)
legend('line1','line2','line3','line4')
hold on
plot([1,100],[0,0],'k-')
Run Code Online (Sandbox Code Playgroud)

用图例绘制四条数据线,然后为 y=0 添加一条黑线。然而,从 R2017a 开始,这导致图例中添加了黑线,名称为“data1”。

如何防止将此行添加到图例中,以便代码的行为就像在旧版本 MATLAB 中一样?

到目前为止,我在 Stack Overflow 上找到的唯一解决方案是在添加图例项后将其删除。语法不太漂亮:

h = plot([1,100],[0,0],'k-'); % keep a handle to the added line
set(get(get(h,'Annotation'),'LegendInformation'),'IconDisplayStyle','off');
Run Code Online (Sandbox Code Playgroud)

matlab plot legend matlab-figure

2
推荐指数
1
解决办法
493
查看次数

OSError:未找到 Octave-cli,请参阅 README

我使用 pip 和 GNU Octave 安装 oct2py。当我在 VScode 中使用 jupyter 时。当我运行: import oct2py 我收到以下错误

OSError:未找到 Octave-cli,请参阅 README

我该如何解决这个问题?

python octave visual-studio-code oserror

2
推荐指数
1
解决办法
4091
查看次数