小编itc*_*lpl的帖子

扫描数据类型错误

我有一个.dat文件的时间序列数据的选项,所以它包括交易日期和到期日期,以及我想在R中进行时间序列分析的价格数据.我是R的新手,所以我一直关注一些在线示例.在我尝试将数据上传为数据框时,我尝试了scan(),但是我收到以下错误:

Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  : 
  scan() expected 'a real', got '2010-Aug-09,2011-Aug-19,C00026000,0.23985,5.53,0.999999,0.00712328'
Run Code Online (Sandbox Code Playgroud)

我知道它期待真实,但我需要输入日期和选项代码来理解时间序列,所以有人可以给我一些关于我如何去做它的指导.thx.

r

8
推荐指数
2
解决办法
3万
查看次数

使用from_string和提升日期

我有以下代码:

    #include <iostream>
#include <string>
#include <iomanip>
#include <locale>


#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/date_time/gregorian/parsers.hpp>

#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/posix_time/posix_time_io.hpp>

using namespace boost::posix_time;
using namespace boost::gregorian;


int main(int argc, char *argv[])
{
 std::string ds("2011-01-02");
date dt(from_string(ds));
date_facet *f=new date_facet("%Y-%m-%d");

 std::locale loc=std::locale(std::locale::classic(),f);
std::cout.imbue(loc);


   std::cout<<dt<<std::endl;


  return 0;

}
Run Code Online (Sandbox Code Playgroud)

当我编译它时,我收到以下错误:

/tmp/ccBWTFcx.o: In function `unsigned short boost::date_time::month_str_to_ushort<boost::gregorian::greg_month>(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
   b.cpp:(.text._ZN5boost9date_time19month_str_to_ushortINS_9gregorian10greg_monthEEEtRKSs[unsigned short boost::date_time::month_str_to_ushort<boost::gregorian::greg_month>(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)]+0x97): undefined reference to `boost::gregorian::greg_month::get_month_map_ptr()'
    collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

这是图书馆链接问题吗?

c++ string locale boost-date-time

7
推荐指数
1
解决办法
5243
查看次数

从C++程序运行perl程序

我有一个C++程序来计算库存,当它低于某个水平时,我想调用我的perl程序,它将订单详细信息写入数据库.我阅读了从C++调用Perl的文档,我正在尝试这个示例代码

#include <EXTERN.h>
#include <perl.h>
static PerlInterpreter *my_perl;
int main(int argc, char **argv, char **env)
{
    char *args[] = { NULL };
    PERL_SYS_INIT3(&argc,&argv,&env);
    my_perl = perl_alloc();
    perl_construct(my_perl);
    perl_parse(my_perl, NULL, argc, argv, NULL);
    PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
    /*** skipping perl_run() ***/
    call_argv("showtime", G_DISCARD | G_NOARGS, args);
    perl_destruct(my_perl);
    perl_free(my_perl);
    PERL_SYS_TERM();
}
Run Code Online (Sandbox Code Playgroud)

我试图编译,但我得到以下错误

g++ fn-test.cpp -o t 'perl -MExtUtils::Embed -e ccopts -e ldopts'
g++: perl -MExtUtils::Embed -e ccopts -e ldopts: No such file or directory
fn-test.cpp:2:24: fatal error: EXTERN.h: No such file or directory …
Run Code Online (Sandbox Code Playgroud)

c++ perl

4
推荐指数
1
解决办法
4295
查看次数

将日期类转换为字符串

我有一个Date类

class Date { int dd, mm, yyyy};
Run Code Online (Sandbox Code Playgroud)

我写了3的规则,一切正常.我想将Date转换为字符串.我需要转换运算符字符串()来执行此操作吗?谢谢!

c++

3
推荐指数
1
解决办法
435
查看次数

汇总R中的时间序列

我有以下OHLC数据(每隔3分钟)

library(tseries)
library(xts)
library(quantmod)
> str(tickmin)
An ‘xts’ object from 2010-06-30 15:47:00 to 2010-09-08 15:14:00 containing:
  Data: num [1:8776, 1:5] 9215 9220 9205 9195 9195 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:5] "zv.Open" "zv.High" "zv.Low" "zv.Close" ...
  Indexed by objects of class: [POSIXct,POSIXt] TZ: 
  xts Attributes:  
 NULL


>tickmin
2010-09-08 15:02:00        20
2010-09-08 15:04:00        77
2010-09-08 15:08:00        86
2010-09-08 15:11:00         7
2010-09-08 15:14:00        43
> start(tickmin)
[1] "2010-06-30 15:47:00 EDT"
> end(tickmin)
[1] "2010-09-08 15:14:00 …
Run Code Online (Sandbox Code Playgroud)

r time-series aggregate-functions

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

用C++编写的mySQL查询

我的C++程序中有以下代码:

query_state = mysql_query(connection, "select * from cplpl");
Run Code Online (Sandbox Code Playgroud)

如果我想用C++程序中的变量替换表名cplpl,我该怎么做?

基本上,我已经创造了

string tblnm="cplpl";
Run Code Online (Sandbox Code Playgroud)

但是如果我跑了

query_state = mysql_query(connection, "select * from tblnm");
Run Code Online (Sandbox Code Playgroud)

它寻找表tblnm.我尝试过$ tblnm,就像你在Perl中可以做到的那样,但这也不起作用

有没有办法解决这个问题?谢谢!

编辑:如果我重写如下:

string tblnm="test";
string qrycd="select * from " +tblnm;
 query_state = mysql_query(connection, qrycd.c_str());
Run Code Online (Sandbox Code Playgroud)

但是,如果我想添加一个where子句,它可以工作

string qrycd1="where fname like '%Bob%';";
Run Code Online (Sandbox Code Playgroud)

并将代码重写为

string qrycd="select * from " +tblnm +qrycd1;
 query_state = mysql_query(connection, qrycd.c_str());
Run Code Online (Sandbox Code Playgroud)

我收到一个错误..

c++ mysql

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

使用提升日期的工作日持续时间

有没有办法只得到没有。2 个提升日期之间的工作日。

在下文中,我只获取日历日。

date begin_dt(2011,Aug,3);
date end_dt(day_clock::local_day());
days duration=end_dt-begin_dt;

std::cout<<"calendar days between begin & end date are: "<<duration<<std::endl;
Run Code Online (Sandbox Code Playgroud)

c++ boost boost-date-time

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

在R中绘制时间序列

我正在处理数据,前两列是日期,第三列是符号,第四和第五列是价格.所以,我创建了一个数据子集如下:

test.sub<-subset(test,V3=="GOOG",select=c(V1,V4)
Run Code Online (Sandbox Code Playgroud)

然后我尝试使用以下方法绘制时间序列图

as.ts(test.sub)
plot(test.sub)
Run Code Online (Sandbox Code Playgroud)

好吧,它给了我一个散点图 - 不是我想要的.所以,我试过plot(test.sub[1],test.sub[2]) ,现在我收到以下错误:

Error in xy.coords(x, y, xlabel, ylabel, log) : 
  'x' and 'y' lengths differ
Run Code Online (Sandbox Code Playgroud)

确保没有.行是相同的,我跑了nrow(test.sub[1]),nrow(test.sub[2])他们都返回相同的行,所以作为R的新手,我不知道修复是什么.

我也跑plot.ts(test.sub)了,但它没有显示x轴上的日期,它正在做什么,plot(test.sub)这是我想看到的.

test.sub[1]
              V1
1107 2011-Aug-24
1206 2011-Aug-25
1307 2011-Aug-26
1408 2011-Aug-29
1510 2011-Aug-30
1613 2011-Aug-31
1718 2011-Sep-01
1823 2011-Sep-02
1929 2011-Sep-06
2035 2011-Sep-07
2143 2011-Sep-08
2251 2011-Sep-09
2359 2011-Sep-13
2470 2011-Sep-14
2581 2011-Sep-15
2692 2011-Sep-16
2785 2011-Sep-19
2869 2011-Sep-20
2965 2011-Sep-21
3062 2011-Sep-22
3160 2011-Sep-23
3258 2011-Sep-26
3356 …
Run Code Online (Sandbox Code Playgroud)

plot r time-series

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

拟合分布到R中的数据

我正在使用R fitdist中的fitdistrplus包中的函数.我有以下数据(我读过使用read.table):

A <- structure(list(V1 = c(-0.00707717, -0.000947418, -0.00189753, 
-0.000474947, -0.00190205, -0.000476077, 0.00237812, 0.000949668, 
0.000474496, 0.00284226, -0.000473149, -0.000473373, 0, 0, 0.00283688, 
-0.0037843, -0.0047506, -0.00238379, -0.00286807, 0.000478583, 
0.000478354, -0.00143575, 0.00143575, 0.00238835, 0.0042847, 
0.00237248, -0.00142281, -0.00142484, 0, 0.00142484, 0.000948767, 
0.00378609, -0.000472478, 0.000472478, -0.0014181, 0, -0.000946522, 
-0.00284495, 0, 0.00331832, 0.00283554, 0.00141476, -0.00141476, 
-0.00188947, 0.00141743, -0.00236351, 0.00236351, 0.00235794, 
0.00235239, -0.000940292, -0.0014121, -0.00283019, 0.000472255, 
0.000472032, 0.000471809, -0.0014161, 0.0014161, -0.000943842, 
0.000472032, -0.000944287, -0.00094518, -0.00189304, -0.000473821, 
-0.000474046, 0.00331361, -0.000472701, -0.000946074, 0.00141878, 
-0.000945627, …
Run Code Online (Sandbox Code Playgroud)

r distribution

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

用时间序列数据绘制stl

我正在尝试使用stl来分析我的时间序列数据中的季节和趋势.我有tick数据,我创建了一个ts对象.

我运行了一个SQL查询来获取下面表单中的数据

    > x
         datetime       price
1  2010-09-08 1501        9110
2  2010-09-08 1501        9110
3  2010-09-08 1501        9110
4  2010-09-08 1501        9110
5  2010-09-08 1501        9115
6  2010-09-08 1501        9115
7  2010-09-08 1501        9110
8  2010-09-08 1502        9115
9  2010-09-08 1502        9115
10 2010-09-08 1502        9115
11 2010-09-08 1503        9120
12 2010-09-08 1503        9115
13 2010-09-08 1503        9115
14 2010-09-08 1503        9115
15 2010-09-08 1503        9115
16 2010-09-08 1503        9115
17 2010-09-08 1503        9115
18 2010-09-08 1503        9115
19 2010-09-08 …
Run Code Online (Sandbox Code Playgroud)

r time-series

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

头文件中的仿函数

我有以下仿函数,我把它包含在我的主程序中

template<class T> struct Comp: public binary_function<T, T, int>
{
 int operator()(const T& a, const T& b) const
 {
   return (a>b) ? 1: (a<b) ? -1 :0;
 }
};
Run Code Online (Sandbox Code Playgroud)

当它在.cpp中时没有给出任何错误,但现在当我将它移动到我的.h时,它给了我以下错误:

testclass.h: At global scope:
testclass.h:50:59: error: expected template-name before ‘<’ token
testclass.h:50:59: error: expected ‘{’ before ‘<’ token
testclass.h:50:59: error: expected unqualified-id before ‘<’ token
Run Code Online (Sandbox Code Playgroud)

所以,我把它重写为:

template<class T> T Comp: public binary_function<T, T, int>
{
 int operator()(const T& a, const T& b) const
 {
   return (a>b) ? 1: (a<b) ? …
Run Code Online (Sandbox Code Playgroud)

c++ functor

0
推荐指数
1
解决办法
1104
查看次数

字符串替换

我有以下字符串./test ,我想用它替换它test ,我在perl中写了以下内容: my $t =~ s/^.//; 但是,替换./test/test 任何人都可以建议我如何解决它所以我也摆脱了它/.谢谢!

string perl substitution

0
推荐指数
1
解决办法
171
查看次数